Last active
September 8, 2015 08:15
-
-
Save qizhihere/b62a17173ce714f89be8 to your computer and use it in GitHub Desktop.
select/unselect all table rows using jQuery
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* disable text selection at double clicking */ | |
$.fn.disableSelection = function() { | |
return this.attr('unselectable', 'on') | |
.css({ | |
'-moz-user-select': '-moz-none', | |
'-moz-user-select': 'none', | |
'-o-user-select': 'none', | |
'-khtml-user-select': 'none', | |
'-webkit-user-select': 'none', | |
'-ms-user-select': 'none', | |
'user-select': 'none' | |
}) | |
.bind('selectstart', false); | |
}; | |
/* select/unselect all items */ | |
$('#table-list-select-all').on('click', function() { | |
var target = $(this).prop('checked') ? ':not(:checked)' : ':checked'; | |
$('tbody#table-list input[type=checkbox]' + target).trigger('click'); | |
}); | |
/* select/unselect current row when clicking the checkbox */ | |
$('tbody#table-list tr input[type=checkbox]').on('click', function(e) { | |
$(this).parents('tr').toggleClass('warning'); | |
e.stopPropagation(); | |
}); | |
/* select/unselect current row when clicking the row */ | |
$('tbody#table-list tr').on('click', function(e) { | |
$(this).find('input[type=checkbox]').trigger('click'); | |
e.stopPropagation(); | |
}).disableSelection(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment