Posts
6
Comments
22
Trackbacks
0
My jQuery cheat sheet

I want to put in this post some the jQuery methods that I found myself searching the web every other time i need them for the future reference.

Check if element exists:
if ($('#elementID').length > 0)
{
   // do somehting
}
Disable/enable element
$('#elementID').attr('disabled', 'disabled');
$('#elementID').removeAttr('disabled');
Clear DropdownList or ListBox
$('#ddl_ID >option').remove();
Add entry in the DropDownList or ListBox
$('#ddl_ID').append($('<option></option>').val(1).html('Text'));
Getting the text and value of the selected item in DropDownList
var selectedValue = $('#ddl_ID').val() or $('#ddl_ID option:selected').val() ;
var selectedText = $('#ddl_ID option:selected').text();
Check/uncheck checkbox:
$('#id]').attr('checked', true);
$('#id').attr('checked', false);
Check if checkbox is checked:
$('#id').is(':checked');
Check if element is disabled
$('#id').is(':disabled');
Check if element is visible/hidden
$('#id').is(':visible')
$('#id').is(':hidden') 

There are a lot of resources available. I like stackoverflow.com. Here is a nice topic - jQuery Tips and Tricks (http://stackoverflow.com/questions/182630/jquery-tips-and-tricks)

And there is one more to dig - jQuery HowTo (http://jquery-howto.blogspot.com/)

more to come...

Technorati Tags: ,
posted on Wednesday, December 16, 2009 8:28 PM Print
Comments
Gravatar
# re: My jQuery cheat sheet
Catherine Russell
2/17/2010 7:33 PM
Thanks for sharing! Good job!
Gravatar
# re: My jQuery cheat sheet
Vladimirl
2/17/2010 8:09 PM
:) You wellcome

Post Comment

Title *
Name *
Email
Url
Comment *  
 
Tag Cloud