jeudi 30 août 2018

How to select checkboxes based on text content?

I have a table with multiple checkboxes. In JavaScript/JQuery I want to select all of them but a couple based on the text content in that table data. So, it should select all checkboxes except if the text content is equal to '899', etc. This is what I have currently:

`

$('#select-all').click(function (event) {
            if (this.checked) {
                var items = document.getElementsByClassName('col-store_number');
                for (var i = 0; i < items.length; i++) {
                    if (items[i].textContent === 899) {
                        items[i].checked = false;
                    } else {
                        items[i].checked = true;
                    }
                }
           }

    });

` When I check the select all box it doesn't select anything, so its likely making them all false instead of just the 899 one. I did a console.log(items[i].textContent); and it did return the right values, so I'm getting the right text content.




Aucun commentaire:

Enregistrer un commentaire