jQuery Cheat Sheet - SEIR-59/course-wiki GitHub Wiki
- window.onload
$(() => {
// code inside jQuery window onload
});
-
this:
$(this)
-
create element:
$('<div>')
,$('<p>')
, etc. -
select all elements of type:
$('div')
,$('p')
, etc.
^^ The two commands above are very similar but they do completely different things!
-
you can get the body of the document with:
$('body')
-
get element by id:
$('#idName')
-
get elements by class:
$('.className')
-
set id on element:
jQueryElement.attr('id', 'idName')
-
set class on element:
jQueryElement.addClass('className')
-
append elements:
jQueryElement.append( jQueryElement )
-
get the parent of an element:
jQueryElement.parent()
-
get child elements:
jQueryElement.children()
-
set an event listener:
jQueryElement.on('click', function() {} )
-
click listener:
jQueryElement.click( function() {} )
-
get value from input box after click:
$('#idName').val()
-
prepend elements:
jQueryElement.prepend( jQueryElement )
-
remove elements:
jQueryElement.remove()
-
set text inside element:
jQueryElement.text("some text")
-
set html inside element:
jQueryElement.html("<some html>")
-
check if element has a class:
jQueryElement.hasClass('someClass')
-
remove a class from an element:
jQueryElement.removeClass('someClass');
-
empty an element of content:
jQueryElement.empty()
-
set a css property on an element:
jQueryElement.css('property', 'value')
-
clone an element:
jQueryElement.clone()
-
append an element with the order reversed:
jQueryElement.appendTo( jQueryElement )
-
get a specific jQuery element from a list:
jQueryCollection.eq( indexNum )