3. Variables - Which way is better?


#1



https://www.codecademy.com/courses/web-beginner-en-GfjC6/0/3?curriculum_id=50a3fad8c7a770b5fd0007a1


It seems like these both work, is there a better way to do this, maybe using the nth-child function? Just making sure I'm figuring this out correctly...

using 'class'...

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

OR

using 'id'....

$(document).ready(function() {
var $target = $('#chumps');
$target.fadeOut('fast');
});


Thanks in advance!


#2

Both methods work fine, why should one be better then the other? Why can't there be multiply good ways to solve a problem?

You can also use nth-child, since you want to target the 4th list element, use:

var $target = $('li:nth-child(4)');

since you know nth-child, i assumes you know how this works?


#3

Works for me! I like that there are multiple ways to solve the problem!

thx!


#4

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