Resolve wrong message during the selection of items by checkbox
In a list page If i checked the header checkbox, system showing wrong message "4 ITEM(S) SELECTED" but there only 3 items present
On a listing page there 3 items are present, but when I select the select all checkbox system showing 4 items is selected. There is a variable "countCheckedCheckboxes" that define the length of the table values. At first, I think if I decremented the countCheckedCheckboxes value 1 then it's OK.
But there is a problem if the counted total length value is always countCheckedCheckboxes -1 then the first checkbox length always be counted as 0(zero).
That why i set a new class on
that count the lenght of content.
$(document).ready(function(){
var checkboxes = $('input[type="checkbox"]');
checkboxes.click(function(){
var countCheckedCheckboxes = checkboxes.filter(':checked').length;
if(countCheckedCheckboxes > 0){
$('.label_info').text(countCheckedCheckboxes-1+' item(s) selected');
}else{
$('.label_info').text('No item selected');
}
});
});
$(".checkSelect").change(function () {
var lenghtCheck= $('input[class="checkSelect"]:checked').filter(':checked').length //that check the length of table content's
//the variable lenghtCheck that count the length of table content.
if( lenghtCheck > 0){
$('.label_info').text(lenghtCheck+' item(s) selected');
}else{
$('.label_info').text('No item selected');
}
});
Conclusion:
You can use the code in NodeJS development. Please share your reviews in the comment section. See you on my next blog.
TOP CATEGORY
LATEST BLOGS
SEO vs AEO: How Search Rankings and Instant Answers Are Reshaping Content Marketing in 2026
SEO
Google AI Overviews SEO: How to Optimize Content for AI Search
SEO
Is SEO Dead? The New SEO Model After Google AI Overviews
SEO
Why Building Topic Authority Matters More Than Individual Keywords
SEO
The Hidden SEO Power of Product Comparison Pages
SEO
GEO for eCommerce: How Product Pages Can Appear in AI Recommendations
eCommerce
Comments