Willy Willy - 6 months ago 21
jQuery Question

How to target specific list item in jQuery?

I have the following HTML & JQUERY:



$(document).ready(function() {
$target = $('number4');
$target.fadeOut('fast');
});

<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div>Remember!
<ul>
<li>
<ol>
<li class='hi'>Start with the function keyword</li>
<li>Inputs go between ()</li>
<li>Actions go between {}</li>
<li class='number4'>jQuery is for chumps!</li>
</ol>
</li>
<li>Inputs are separated by commas.</li>
<li>Inputs can include other functions!</li>
</ul>
</div>





I wanted the four element in my ordered list to fadeout when the document is ready, but it is not working. I tried identifying the fourth ordered list element with class='number4' and then targeting that identifier in the jQuery, but it is not working. Any suggestions?

Answer

Probably this works

 $(document).ready(function() {
   $target = $('.number4');
   $target.fadeOut('fast');
 });