3 variables


i don't understand the instruction n what i have to do..
can someone give me correct script?


You will have to define a $target variable
before you can use the fadeOut() Method......

$(document).ready(function() {
//    var $target=$('ol li:last-child');
//    var $target=$('ol li:nth-child(4)');
//    var $target=$('ol li:contains("chumps")')
    var $target=$('ol, li:contains("can")')
//    var $target = $("li:last-child")

//    $target.fadeOut('fast');
// direct targeting, remove/add // per line
//    $('html').text('=target0=');
//    $('html>body>div>ul>li').text('=target1=');
//    $('html>body>div').text('=target2=');
//    $('li>nth-child(3)').text('=target3=');
//    $('li').text('=target4=');
//    $('ul>li:nth-child(3)').text('=target5=');
//    $('ul li:nth-child(3)').text('=target6=');
//    $('ol li:nth-child(3)').text('=target7=');
//    $('ol').hide(); 

For documentation
use google search
== the Book ==
fadeOut() site:jquery.com

Also have a look at the DOM representation of the index.html



ok thanks ..:slight_smile:
but what is the difference between
this script:

var $target=$("ol li:nth-child(4)")

and this script:
$target=$("ol li:nth-child(4)")




google search
=the book=
javascript variable site:developer.mozilla.org


Hi There!

Instead of using :nth-child(), I defined #4 some class in my html document and then used selector to define in jquery.
It looks like:
li class="fademe">jQuery is for chumps!

and my jquery code was:

$(document).ready(function() {
$target= $(".fademe");

Is this a good way?


Just mentioning this, because this is the problem i had with my code.

// Write your jQuery code on line 3!
$(document).ready(function() {
    var $target = $(li:last-child)

don't forget your " "s. this was a simple fix, but it took me a while.

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


With respect, after some review of CSS selector rules as well as some trial and error with the variable declarations offered by leonhard, it appears that a few of the suggested jQuery variable declarations do not yield the desired result of omitting the line referring to jQuery users being "chumps".

The first three variable declarations suggested:

var $target=$('ol li:last-child');
var $target=$('ol li:nth-child(4)');
var $target=$('ol li:contains("chumps")');

when utilized by referencing the $target object:


will fade the line:

"jQuery is for chumps!"

That said however, when experimented with, the variable declarations:

var $target=$('ol, li:contains("can")')
var $target = $("li:last-child")

appear not to be very selective in what they'll play a role in fading out.

Wouldn't it be best for the purposes of clarity to omit the last two declarations just referenced?

Again, with respect.