ComeRun
ComeRun

Reputation: 921

jQuery select, regarding ie6

given the following html:

<ul class="accordion">

  <li class="accountStatus">
    <a href="#">
    <ul class="sub-menu"></ul>
  </li>

  <li class="Personal">
    <a href="#">
    <ul class="sub-menu"></ul>
  </li>

</ul>

I know the following jquery select works fine for the two elements (a and sub-menu):

$('.accordion > li > a')
    $('.accordion li > .sub-menu');

But this does not work in ie6. so would anyone please give me another alternative to select the exact elements that need to be selected.

Thanks,

Upvotes: 0

Views: 56

Answers (1)

Paul S.
Paul S.

Reputation: 66324

One way could be to get all the nodes using methods you know you have in IE6, then convert to jQuery objects before continuing, e.g. (& fiddle)

var all_uls = document.getElementsByTagName('ul'), i = all_uls.length, 
    interesting_uls = [], interesting_as = [];
while (i--) {
    if (all_uls[i].className === 'accordion') {
        // get ul.accordion
        interesting_uls.push(all_uls[i]);
    }
}
all_uls = interesting_uls, i = all_uls.length; // reset for next class lookup
while (i--) {
    if (all_uls[i].className === 'sub-menu') {
        // get ul.accordion ul.sub-menu
        interesting_uls.push(all_uls[i]);
    }
    // get <a>s
    interesting_as = interesting_as.concat(all_uls[i].getElementsByTagName('a'));
}
$(interesting_uls); // to jQuery obj
$(interesting_as);

Upvotes: 1

Related Questions