Created by
$(selector).action()
$("div").hide() - hides all <div> elements.
$(".red").hide() - hides all elements with class="red"
$("#vip").hide() - hides the element with id="vip"
$(this).hide() - hides the current element.
jQuery
and $
$
is just an alias for jQuery
and it's often employed because it's shorter and faster to write
$( document ).ready(function() {
// Your code here.
});
// Shorthand for $( document ).ready()
$(function() {
// Your code here.
});
// by ID:
$( "#vip" );
// by class name:
$( ".red" );
// by attribute selector:
$( "input[target='_blank']" );
// by pseudo-elemement selector:
$( "div:nth-of-type(1)" )
$(".title").click();
$( 'selector' ).eventMethod( eventHandlerFunction );
$('.title').click(function (e) {
$(this).css('color','red');
})
$('.item').on('click', function (e) {
$(this).css('color','red');
})
$('.title').click(function (e) {
console.dir(e);
$(this).css('color','red');
})
this
' refers to the DOM element that initiated the event.$(this)
to convert the DOM object to jQuery Objectparent()
- returns immediate parentparents()
- returns ancestors
// get parents of all selected children:
$('.child').parent().css('background', 'yellow');
// get parents with class='uncle' of all selected children:
$('.child').parent('.uncle').css('background', 'orange')
text()
- Sets or returns the text content of selected elementshtml()
- Sets or returns the content of selected elements (including HTML markup)val()
- Sets or returns the value of form fieldsA simple yet powerful responsive jQuery image gallery.
These slides are based on
customised version of
framework