jQuery selecting common children in a deep tree

we're looking for a way to select common sibilings in a complex structure... the problem is that the known element is deep within the tree... what we need to find is the common parent dynamically and then select the similar children... without knowing who the common parent is...

eg, we need to find siblings of div.childA

table
--tr
----td
------div.childA
--tr
----td
------div.childA
--tr
----td
------div.childA

in the above example how would you select all the childA siblings without knowing who the common parent is and the possibility of div.childA existing somewhere else on the page...

the code should also be able to handle other structures such as

div
--span
----div
------h1
--------span.childA
div
--span
----div
------h1
--------span.childA
div
--span
----div
------h1
--------span.childA
div
--span
----div
------h1
--------span.childA

again need to select all childA, there is also no guarantee that childA has the same class but we can assume that the structure is common for the repeating elements... we just don't know the specific depth.

Answers


Assuming they have class of childA can easily obtain parent by looping over the collection:

$('.childA').each(function(){
   $(this).parent().addClass('parentOfChildA')
})

Would be <td> in first example and <h1> in second.


Need Your Help

Do we need Record Level Locking when we already have Transaction for online ordering? (of concert ticket or airline booking)

transactions rdbms database record-locking

For online ordering of concert seats or airline tickets, do we need Record Level Locking or is Transaction good enough?

Getting Unity to Resolve views in XAML

xaml mvvm dependency-injection unity-container cinch

I'm starting out with MVVM, and I'm starting to understand things. I'm currently experimenting with the Cinch framework, though I'm not committed to it as of yet.