Jquery Selectors Quick Quide
9th Sep 2010 at 8:08 AM | Posted in Jquery | Leave a 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
});
});
});
Blog at WordPress.com. | Theme: Pool by Borja Fernandez.
Entries and comments feeds.
