3 variables


#1

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


#2

@owlsz,
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")')
    $target.fadeOut('fast');
//    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

https://www.codecademy.com/forum_questions/55815ef69113cb48b7000111


#3

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)")


#4

@owlsz,

Reference::

google search
=the book=
javascript variable site:developer.mozilla.org
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/var
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Values,_variables,_and_literals


#5

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");
$target.fadeOut('fast');
});

Is this a good way?


#7

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)
    $target.fadeOut('fast');
});

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')
    $target.fadeOut('fast');
});

#8

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:

$target.fadeOut('fast');

will fade the line:

"jQuery is for chumps!"

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

var $target=$('ol, li:contains("can")')
or
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.