Check if checkbox is checked with jQuery
- Article
- Comment
Check if checkbox is checked with jQuery. There are few ways available to check the Checkbox by using jQuery. Let’s start with my preferred way. I always use is() function to check a property. Let’s start with an example. The following code is one of a very simple function to check the check-box property
if($("#KvcodesCheckBoxName").is(':checked')) { $("#div_id_kvcodes").show(); } else { $("#div_id_kvcodes").hide(); }
Let’s see an another way by using Toggle function. This one is also quite Easy and less code work while compare with first one.
$('#KvcodesCheckBoxName').click(function () { $("#Div_id").toggle(this.checked); });
This is also quite simple one, also, few other methods also available, You can try regular expressions as well.
$("#KvcodesCheckBoxName").attr("checked") ? $("#div_id_kvcodes").show() : $("#div_id_kvcodes").hide();
This function is also easy to go. inline method. Next is another simple way to use it. Its Prop Method, used widely for many operations.
if($('#KvcodesCheckBoxName').prop('checked')) { //Code goes here... }
These are all the most used functions, you can try either one to get results.