3. Variables - Which way is better?



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');


using 'id'....

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

Thanks in advance!


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?


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



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