CodePamoja
CodePamoja means "Code Together" in Swahili. We are a group of passionate developers in The Netherlands and Kenya working together in virtual teams, transferring the latest software development skills to each other.
// Selecting elements matching a name
$('div')
$('p')
// Selecting a single element matching the ID
$('#idname')
$('div#idname')
// Selects all elements matching the Class name
$('.classname')
$('.firstclass.secondclass')
// Selects all available elements
$('*')
// Selects a combination of selectors
$('article, p')
$('p strong, .classname')
// Set a key/value as a property to all matching elements
selector.attr({property1:value1, property2:value2})
$('img').attr({ src: '/img/logo.jpg', alt: 'Company logo'});
// Remove an attribute from the matching elements
selector.removeAttr(name)
$('button').removeAttr('border');
// Removes class from the set of matching elements
selector.removeClass(class)
$('p').removeClass('block');
// Add a class if it's not presents and removes a class when it is present
selector.toggleClass(class)
$(document).ready(function() {
$('div.bar').click(function () {
$(this).toggleClass('display-text');
});
});
// Preventing the browser from executing a default action
event.preventDefault()
// Preventing any parent handlers being notified of an event
event.stopPropagation()
// Stops the handlers from being executed
event.stopImmediatePropagation()
// Binds a handler to one or more events for matching elements or custom events
selector.bind(type, [data], fn)
$(document).ready(function() {
$('.btn').bind('click', function(event){
alert('You just clicked on me!');
});
});
// Removing bound events from matching elements
selector.unbind([type], [fn])
// Creates a hover effect on an object
selector.hover(over, out)
$(document).ready(function() {
$('btn').hover(
function () {
$(this).css({'border': '1px solid black'});
},
function () {
$(this).css({'border': '1px solid red'});
}
);
});
// Function will be executed when the DOM is ready
selector.ready(fn)
// To trigger an every on matching elements
selector.trigger(event, [data])
// Showing and hiding elements
[selector].show(speed, [callback]);
[selector].hide(speed, [callback]);
// Toggling the state of elements
[selector]..toggle([speed][, callback]);
// Fading in elements by adjusting opacity
selector.fadeIn(speed, [callback]);
// Fading out elements by adjusting opacity
selector.fadeOut(speed, [callback]);
// Example fadeIn and fadeOut
$(document).ready(function() {
$("#in").click(function(){
$(".block").fadeIn( 'slow', function(){
$(".content").text('Fading in');
});
});
$("#out").click(function(){
$(".block").fadeOut( 'slow', function(){
$(".content").text('Fading out');
});
});
});
By CodePamoja
CodePamoja means "Code Together" in Swahili. We are a group of passionate developers in The Netherlands and Kenya working together in virtual teams, transferring the latest software development skills to each other.