I cannot get this simple code to work. I want to get the value from the data attribute and based on that pass it to the alert
http://jsfiddle.net/btL9C/
$("input[type=checkbox]").change(function() {
var section_list = $('.section').data('section_list');
if ($(this).hasClass(section_list+"_list")) {
alert(section_list);
}
});
html:
<input type="checkbox" data-section_list = "1" class="section 1_list">
<input type="checkbox" data-section_list = "2" class="section 2_list">
<input type="checkbox" data-section_list = "3" class="section 3_list">
How can I get the alert to display the corresponding value of data-section_list?
Try this
$("input[type=checkbox]").change(function() {
var section_list = $(this).data().section_list;
if ($(this).hasClass(section_list+"_list")) {
alert(section_list);
}
});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With