javascript - Find a specific text in tr td jquery using contains -


this question has answer here:

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

Popular posts from this blog

python - pip install -U PySide error -

arrays - C++ error: a brace-enclosed initializer is not allowed here before ‘{’ token -

cytoscape.js - How to add nodes to Dagre layout with Cytoscape -