user1559555
user1559555

Reputation: 167

jquery next() issue

I have code like so:

var parent = $("#delete-button").closest('div');
var head = parent.prev('h3');
var linktext = head.next('a');

the code up to:

var parent = $("#delete-button").closest('div');
var head = parent.prev('h3');

works fine, I'm able to use both parent and head vars, however:

var linktext = head.next('a');

does not seems to be working fine, because:

alert(linktext.html());

returns null


HTML (no div and #delete-button, sorry):

<h3 class="ui-accordion-header ui-helper-reset ui-state-default ui-corner-all" role="tab" aria-expanded="false" aria-selected="false" tabindex="0">
    <span class="ui-icon ui-icon-triangle-1-e"></span>
    <a href="#" tabindex="-1">first</a>
</h3>

Upvotes: 0

Views: 65

Answers (1)

Aadaam
Aadaam

Reputation: 3739

Because next searches for siblings (and only IMMEDIATE siblings, if the selector is not matched, it returns an empty set), while you're searching for a child. Try

head.find('a')

instead.

Upvotes: 1

Related Questions