Use element ownerDocument instead of document