Friday, 13 May 2016

javascript - How to show/hide HTML elements with checkboxes



I was trying to create a checkbox checked by default for an ecommerce website, I want to show the div when the checkbox is unchecked. and hide the div when the checkbox is checked.



 My Fiddle: http://jsfiddle.net/ScnQT/3161/ 

Answer




You can check whether checkbox is checked using $(this).prop('checked')



if checked $(this).prop('checked') returns true else false



for more details here



Updated fiddle






$('.shipping_address_details').hide();
$('#checkedforShippingAddress').change(function(){

if($(this).prop('checked')){
$('.shipping_address_details').hide();
}else{
$('.shipping_address_details').show();
}
});






Ship to the same address




Shipping Address












































No comments:

Post a Comment

c++ - Does curly brackets matter for empty constructor?

Those brackets declare an empty, inline constructor. In that case, with them, the constructor does exist, it merely does nothing more than t...