user1937021
user1937021

Reputation: 10771

FInd content of child of a sibling of an element

I need to get the content of the child of a sibling of an element:

i.e. using the id of the input element I need just the text of the button element below, i.e. "All packages"

<input type="hidden" value="0" id="packages" name="packages">
<div class="btn-group">
<button data-label="All Packages" data-toggle="dropdown" class="btn dropdown-toggle disabled">All Packages <span class="caret"></span></button>
</div>

I've tried the following:

var packageBtnFilter = $('#packages').next('div.btn-group').find('.btn').text;

but to no avail.

Upvotes: 1

Views: 98

Answers (2)

Kanishka Panamaldeniya
Kanishka Panamaldeniya

Reputation: 17566

var packageBtnFilter = $('#packages').next('div.btn-group').find('.btn').text()

Upvotes: 1

gdoron
gdoron

Reputation: 150253

text is a function not a property:

var packageBtnFilter = $('#packages').next('div.btn-group').find('.btn').text;
//                                                                       ^^^^

Should be:

var packageBtnFilter = $('#packages').next('div.btn-group').find('.btn').text();
//                                                                       ^^^^^^

Upvotes: 4

Related Questions