I am creating this shopping list app. The app is working fine but I am facing an issue with delete button. I want to show a button when I check the check box. It is happening in current app but it is populating the delete button for all the items in the list.
I only want to populate it for the checkbox that I select, I mean where I have checkbox selected and strikethrough applied.
Sample code -
/*Checkbox Strikethrough Item Text */
$('input.check').change(function(){
$(this).siblings('.item').toggleClass('strike');
$('.delete_item').removeClass('hidden');
});
You can find full working code at this JS Fiddle -
http://jsfiddle.net/varunksaini/Zjxq5/
$(this).parents('li').find('.delete_item').removeClass('hidden');
通过单击复选框的父级来查找与“ li”选择器匹配的元素,并使用delete_item类找到其子级并将其显示。
See
/*Checkbox Strikethrough Item Text */
$('input.check').change(function () {
$(this).siblings('.item').toggleClass('strike', this.checked);
$(this).closest('li').find('.delete_item').toggleClass('hidden', !this.checked);
});
Demo: Fiddle
you can do it this way:
$('input.check').change(function(){
$(this).siblings('.item').toggleClass('strike');
$(this).parent().next().removeClass('hidden');
});
$(this).parents('li').children('.delete_item').removeClass('hidden');
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.