Created
May 20, 2013 18:53
-
-
Save internoma/5614413 to your computer and use it in GitHub Desktop.
Jquery DOM
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Add a CSS class to a specific element | |
$('#myelement').addClass('myclass'); | |
// Removing a CSS class from a specific element | |
$('#myelement').removeClass('myclass'); | |
// Check if a specific element has a CSS class | |
$(id).hasClass(class) | |
// Switch CSS using jQuery | |
$('link[media='screen']').attr('href', 'Alternative.css'); | |
// Append HTML to an element | |
$('#lal').append('sometext'); | |
// Check if an element exists | |
if ($('img').length) { | |
log('We found img elements on the page using "img"'); | |
} else { | |
log('No img elements found'); | |
} | |
// Get element siblings | |
$("div").siblings() | |
// Remove an option from a select list | |
$("#selectList option[value='2']").remove(); | |
// Get the selected option as text | |
$('#selectList :selected').text(); | |
// Apply a “zebra” effect on tables | |
$("tr:odd").addClass("odd"); | |
// Count children of an element | |
$("#foo > div").length | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment