Jquery Selectors Quick Quide

9th Sep 2010 at 8:08 AM | Posted in Jquery | 1 Comment
$('select.foo option:selected').val();    // get the value from a dropdown select
$('select.foo').val();                    // get the value from a dropdown select even easier
$('input:checkbox:checked').val();        // get the value from a checked checkbox
$('input:radio[name=bar]:checked').val(); // get the value from a set of radio buttons

Radio Button:

jQuery('#radio_form input:radio:checked').val();
$("#myform input[type='radio']:checked").val();
$('input:radio[name=bar]:checked').val();
$("input[@name='rdio']:checked") . Val();

Checkbox:

$('input:checkbox:checked').val();
$('#checkBox').attr('checked');
$('#edit-checkbox-id').is(':checked');

$("input[@type=checkbox][@checked]").each(
function(){
// Insert code here
} );

$("input[@name='chkBox']").click(function(){
// your code here
});

$("input[type='checkbox']:checked").each(function(){
//Insert code here
});

Drop Down:

$("select option:selected").each(function () {
/Insert cod here
});

Get Selected value:
$('#selectId :selected').val()

Get Selected value Text:
$(<'#selectId :selected').text()

Get Selected Values:
$(document).ready(function() {
$("#a").click(function(){
$("select option:selected").each(function(){
alert($(this).val());//you can create an array here
});
});
});
Advertisements

1 Comment »

RSS feed for comments on this post. TrackBack URI

  1. It seems u really understand plenty about this specific issue and this shows via this amazing post, titled “Jquery
    Selectors Quick Quide | Sourav’s Blog”. Thank you -Junior


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Create a free website or blog at WordPress.com.
Entries and comments feeds.

%d bloggers like this: