jQuery selectors
class selectors
id selectors
other selectors
DOM Manipulation
addClass
append
attr
html
text
hide and show
Class selectors
$('.classname')
ID selectors
$('#id')
element selectors
$(p)
input selectors
$('input [type=text]')
first and last
$('li:first') or $('li:last')
Note: selector can be any possible selector.
Hide and Show
$(selector).hide()
$(selector).show()
addClass
$(selector).addClass('wrap')
append
$('ol').append('<li>new list item</li>')
appendTo
$('<li>new list item</li>').appendTo('ol')
after and before
$(selector).after('hello')
$(selector).before('hello')
html() - gives you the html content of the selector
$(selector).html()
text() -gives you the text content of the selector
$(selector).text()
val() - gives you the value of the form elements
$('input').val()
val(value) - sets the value to the form elements
$('input').val('hello')
Text
Text
more tags...
attr('title') - gets the value of the attribute
$(selector).attr('title')
attr('title', 'value') -sets the value to an attribute
$(selector).attr('title','hello world')
removeAttr() -used to remove an attribute
$(selector).removeAttr( "title" )
some more tags...
General format for writing an event:
$(selector).on('eventname',function(context,event){
//do something
});
var firstDiv=document.getElementById("first")
var secondDiv=document.getElementById("second")
var thirdDiv=document.getElementById("third")
***Never ever make this mistake***
var doc=document
var firstDiv=doc.getElementById("first")
var secondDiv=doc.getElementById("second")
var thirdDiv=doc.getElementById("third")
Write this instead...