0

I am having some issues with getting the list of parents of an element with jQuery.

Perhaps I am missing something, but I have a link inside several nested divs, and am trying to get a list of siblings of the parent's parent.

I only seem to be able to go one level up from the link though, so I can't

The HTML is as follows:

<div class="alertcontainer"> <div id="alertnode_1" class="alertnode"> <div class="alertnodeheader">Escalate to Level 1</div> <div class="alertnodebody"> <div class="bold">Alert these people:</div><br/> <div class="alertnodebodycontactlist"> <div class="alertnodebodycontact">187 <a id="d0.9659762698410487" onclick="RemoveNode(this, 187)" href="#">Remove Me...</a> </div> <div class="alertnodebodycontact">185 <a id="d0.6609632486132389" onclick="RemoveNode(this, 185)" href="#">Remove Me...</a> </div> <div class="alertnodebodycontact">184 <a id="d0.13180038199138278" onclick="RemoveNode(this, 184)" href="#">Remove Me...</a> </div> <div class="alertnodebodycontact">186 <a id="d0.6364304467227213" onclick="RemoveNode(this, 186)" href="#">Remove Me...</a> </div> <select class="esccontactlist" id="esc_contact_list_1"> <option>Also alert...</option> </select> </div> <br/> </div> </div> </div> 

JS/jQuery as follows:

function RemoveNode(e, id) { // Remove the contact $(e).parents().filter('.alertnodebodycontact').remove(); // Add it back into the list. for ( var i = 0; i < ContactList.length; i++) { if ( id == ContactList[i]["ContactID"] ) { $('#esc_contact_list_1') .append("<option value='" +ContactList[i]["ContactID"] +"'>&nbsp;&nbsp;" +ContactList[i]["ContactName"] +" (" +ContactList[i]["PrimaryEmail"] +")</option>"); } // Here, I want to count the number of '.alertnodebodycontact' divs. // However, $(e).parents() only returns a single item, which is the // '.alertnodebodycontact' that the link is in. // Likewise, $(e).parent().parent() returns nothing. // Anyone have any idea why the outer divs aren't being returned? } } 
1
  • Instead of putting inline javascript in the anchor elements, you could bind to the click event of each anchor in $(document).ready() and pass in itself as an argument, along with it's parent text Commented Feb 19, 2009 at 0:03

1 Answer 1

2

Nevermind... I am trying to access it after removing it. Just need to re-order my tasks.

Sign up to request clarification or add additional context in comments.

2 Comments

Thanks for this - made me realize I was doing the same thing. An event called with trigger() wasn't bubbling up and it took this for me realize it was because I was firing the event from the element after it was removed from the DOM :)
Good to know I'm not the only one... =o)

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.