I have a div that has many other divs, each at a different nesting level. Instead of giving each child an identifier, I just want to give it to the original identifier identifier. Here's an example:
& lt; Div class = "a" id = "a5" & gt; & Lt; Div class = "b" & gt; & Lt; Div square = "c" & gt; & Lt; One square = "d" & gt; & Lt; / A & gt; & Lt; / Div & gt; & Lt; / Div & gt; & Lt; / Div & gt; If I write a function in JQuery to answer in class and I want to get the ID for her parent, then class A, how will I do this? I just can not do $ ('. A') Attr ('id'); Because many classes are one I can find the ID of the parents of my parents' parents but it seems that poor design, slow and very multifaceted (to find the ID for class C Have to type different codes). Any ideas SO?
assuming that is .d , You can write $ (this) .closest ('a'); The inner parent of your element matches the selector.
Comments
Post a Comment