jquery - Javascript - event.target.offsetParent -
I am experiencing the following situation:
-
mousemove
The event is registered on one table of cells which resides in this hierarchyBODY - & gt; Some 1 - & gt; Some 2 - & gt; Some 3 - & gt; Table - & gt; Cell
- I will find the ID of the some 2 element to do something with it. In my opinion, the ID should be retrieved in one of the following methods Can be:
-
e.target.offsetParent.offsetParent.offsetParent.id
- which is hard & amp; I do not like it - Loop through all the parents of
e.target
and match the class [Yes, I know the class name of the element] Specific parent I want to retrieve the ID whose ID I have
-
Now, the question is, is there a better way to achieve this? Like some jQuery search or something else?
Example: ($ (E.target) .parents ('. Object'). Length); // This is a result '0' console.log ($ (e.target) .closest ('. Object') length); // This console also applies. ($ (E.target). Parents (). ('Find Object')); // This class selects all the elements with the name 'object' regardless of the e-taraz Be a parent); e.target.findOnOffsetParents ('& lt; .LASS_NAME & gt;'); Edit
depending on what you are searching for, and what you're doing with the result You want to use either
> $ (elem) .parents ('.' Object)
- object
Returns to all parents of elem
with a class of P>
$ (elem) .closest ('. Object')
- elem < / Code> to the first parent, who has a class of
object
I think you want to do that later, which will be:
$ (et Arget) .closest ('. Object')
It shows that each set- is similar to what you have mentioned in your question
Comments
Post a Comment