Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

append input checkbox in jquery

I have input checkbox namely select all. I added the checkbox from jquery end. if user click on select all rest of the option will be checked. but I'm getting error when click on select all. here I'm attaching the code.

$('#multiple_msisdn').append(
'<label class="exp" style="margin-bottom: 5px; display: inline-block;">
 <input type="checkbox" class="exp" onclick="$(input[name=msisdn\\[\\]])
 .attr(checked, this.checked)">-- Select All -- </label>');

error: uncaught syntaxError.

error generated here $(input[name=msisdn\[\]]).attr(checked,> this.checked)

like image 210
hmamun Avatar asked Jun 02 '26 06:06

hmamun


1 Answers

$('#multiple_msisdn').append('<label class="exp" style="margin-bottom: 5px; display: inline-block;"><input type="checkbox" class="exp SelectAll"> -- Select All -- </label>').append('<br><label class="exp" style="margin-bottom: 5px; display: inline-block;"><input type="checkbox" class="exp" name="msisdn[]"> -- 1 -- </label>').append('<br><label class="exp" style="margin-bottom: 5px; display: inline-block;"><input type="checkbox" class="exp" name="msisdn[]"> -- 2 -- </label>');

$(document).on("click",".SelectAll",function(){
  $("input[name='msisdn[]']").prop('checked',$(this).is(':checked'))
})
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div id="multiple_msisdn"></div>
like image 185
Farhad Bagherlo Avatar answered Jun 05 '26 01:06

Farhad Bagherlo



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!