javascript - Find a specific text in tr td jquery using contains -
this question has answer here:
- how can detect if selector returns null? 7 answers
this fiddle of finding text in tr.
i used
var reports = $('table#reports > tbody'); var tr1 = reports.find('tr:has(td:contains("first name"))');
to find text if text not exist still alerts exists. check if exist created if
if (tr1) { alert('exist'); } else { alert('not'); }
the problem .find()(infact traversing methods) return jquery object truthy, condition true.
if want see whether selector found matches can check length property of jquery object give number of dom element references returned selector, if there no matched elements return 0
so
if (tr1.length) { alert('exist'); } else { alert('not'); }
Comments
Post a Comment