Can’t figure out what this isn’t working right. Trying to get each button_select_sub li’s text and put it in an array. Its being built to find the #button_groupings children like it is, cause the functionality behind it is based on the notion that there will be multiple instances of the HTML below. The problem I am having right now is, not so much as it getting the text from each, but however its pushing it into the array is making the array just 1 item, not multiple items.
$('#button_groupings').children('li').children('.button_select_sub').each(function(n,v){listArray.push($(this).text());})
The html for it.
<div class="button_select_header_like_thing">
<div class="button_select">
<ul class="button_select_toggle" id="button_groupings">
<li>
<div class="button_select_text">Menu Text</div><div class="button_select_arrow">V</div>
<div style="clear:both"></div>
</li>
<li>
<ul class="button_select_sub" rel="hidden">
<li>Text</li>
<li>Text</li>
<li>Text</li>
<li>Text</li>
</ul>
</li>
</ul>
</div>
</div>
Do you have a
var listArray;line somewhere in the global scope? If not, the variable would probably be treated as a local variable to that anonymous function.Edit
It looks like you need to go one level deeper before doing the each(). You’re doing .each on the <ul class=’button_select_sub’> element, instead of the li element.
You can also use this slightly easier to read syntax.