I have a table in which I have list of name.
Now I want to delete it by jquery on basis on its text.
$(addrow + " td:contains(" + foodname + ")").parent('tr').next("tr").remove();
I have this which works fine but it have a flaw.
For eg for removing 'xyz',
Case 1: td with text such as xyz,abc,poi etc. ------> it works fine
Case 2: td with text such as xyz,abxyzc,poi etc. ------> removes xyz and xyzabc as well
Is there a direct way to check exact and not contains in td by jquery?
Thank you!
match your td text value with text()
Try below code -
If you want to delete tr
which is next to that 'tr' in which td
matches with the text.
$(addrow).find('td').each(function(){
if($(this).text() == foodname){
$(this).parent('tr').next("tr").remove();
}
});
Or you just want to delete the tr
whose td
matches with the text.
$(addrow).find('td').each(function(){
if($(this).text() == foodname){
$(this).parent('tr').remove(); // don't use next() here
}
});
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.