Odd result, I think my code shouldn't work but it does


#1



Ok, I'm missing something here. My code works but I don't think it should.:

line 4 disappears with the selector var $target = $('ol li:last-child(4))');

which seems odd to me as I thought last-child doesn't need any arguments passed in.

the selector var $target = $('ol li:nth-child(4))');
and the selector var $target = $('ol li:last-child())');
neither of which worked, but passing 4 to last child made the proper list item disappear.

It works, but I don't quite understand why. Is there a better way to select that 4th list item?


// Write your jQuery code on line 3!
$(document).ready(function() {
    var $target = $('ol li:last-child(4))');
    $target.fadeOut('fast');
});


#2

If it is in fact working then the parser is ignoring (4). The pseudo class is :last-child.

You could also use ol li:nth-child(4) as a specific selector.


#3

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.