I have a checkbox, how can I get its value using jquery? I have an example from the search:
var checked = $('input[type=checkbox]:checked').val() != undefined;
but how to indicate which flag I am interested in, I only want to check the flag with a specific identifier?
thank
Even easier
if($('#foo').is(':checked')){ //code here }
var checked = $('input#foo:checked'); if ( checked.length && checked.val().length ) { // do something with checked }
jQuery is() :checked:
is()
:checked
var $theCheckbox = $('#theID'); if( $theCheckbox.is(':checked') ) { var checked = $theCheckbox.val(); }
http://jsfiddle.net/BYagp/1/
? , checked. , , , value.
checked
value
var mybox = $('input#myid'); if (mybox.length > 0 && mybox[0].checked) { // do something, or use mybox[0].value } else { }
Say your id is #myid, then:
var checked = $('input[type="checkbox"]#myid').attr('checked'); if (checked) { //box is checked } else { }
Source: https://habr.com/ru/post/1750566/More articles:ReceiveFromAsync example - c #Why is the "EventHandler cccc public event" null? - c #https://translate.googleusercontent.com/translate_c?depth=1&pto=aue&rurl=translate.google.com&sl=ru&sp=nmt4&tl=en&u=https://fooobar.com/questions/1750563/alternatives-to-static-variables-in-android&usg=ALkJrhgK97qQkZq3-RJO2g5hhnqI9Wm9_gUsing jQuery using Closest ("element.class") - jqueryCreating and initializing an array of vectors at a time - c ++Is it possible to consider a string as one object in a list in MATLAB? - stringOnly attribute attributes are read-only, and how to set them? - perlМожно ли разделить последовательность чисел на две группы, основанные на медианном значении без сортировки? - sortingWhat is the proper way to stop loading a Flex module before it is fully loaded? - flexAre triggers asynchronous? - asynchronousAll Articles