Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Check if td element have certain value

i have a table with number :

<td id="table-number">{{ $loop->index + 1 }}</td>

now i want to get the number of "9" from the table row

Here is what i do :

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

const number = document.getElementById('table-number');


if(number.textContent.includes('9')) {
            console.log('heyhey');
        }

but it returns nothing. So, what should i do? I expect to get the table number.

ok guys, i got the answer at this post, sorry i didnt serach thoroughly. Need to upgrade my google skils

>Solution :

Assuming the <td> elements are produced in a loop and you want to know if any of them contain a 9, give the elements a class instead of id…

<td class="table-number">

and try something like this instead

const tableNumbers = Array.from(
  document.querySelectorAll(".table-number"),
  ({ textContent }) => textContent
);

if (tableNumbers.some((content) => content.includes("9"))) {
  console.log("heyhey");
}
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading