Quotes help make search much faster. Example: "Practice Makes Perfect"

Wednesday, November 7, 2012

Codecademy: Sample Solution to "$ vs $()"



//Sample Solution to script.js
$('document').ready(function() {

//utility method -- by the end of this lesson
//you'll know enought to write it yourself!
function addListItemTo(listId,item) {
    $('#'+listId).append($('<li/>').html(item));
}

var jQuery = $;
var jQueryObject = $();

//iterate over jQuery, adding every key to the list with id
//jQueryAttributes using addListItemTo()
//you just need to write the for loop
for (key in jQuery){
    addListItemTo("jQueryAttributes",key);
}
//iterate over jQueryObject, adding every key to the list with id
//jQueryObjectAttributes using addListItemTo()
//you just need to write the for loop again\
for (key2 in jQueryObject){
    addListItemTo('jQueryObjectAttributes',key2);
}
});

No comments:

Post a Comment


This is an example of scrolling text using Javascript.

Popular Posts