Let's say I have a table with some data in it, and I want to look for a specific string within tbody, I have got this logic:
if ($('.table--cart tbody tr td')) { ... }
Within the table I check if there is a string str within that td.
if ($('.table--cart tbody tr td')[0].innerHTML.indexOf(str) !== -1)){ ... }
But it doesn't work as expected, when I search in my dev tools for table--cart,it returns not found, but the first check passes,resulting in an error undefined is not an object, evaluating $('.table--cart tbody tr td')[0].innerHTML.indexOf(str) !== -1.
Is my first check wrong? I only want to execute the second check when the first one is true, obviously.
:contains()for this issue. api.jquery.com/contains-selector$should come before('.table--cart ...innerHTML, you can tryhtmlinstead.