I have this html. I need to .append certain text based on some conditions:
1) td.name a contains text which triggers append
2) td.name and td.quantity are inside the same row
3) .append is done only in the same row td.name and td.quantity are in.
There are multiple rows. Rows don't have classes and code is dynamically generated - each row may end up on different position in the table. How do I target this
if (jQuery('tbody tr td.name a:contains("text which triggers append")').length > 0) {
jQuery('tbody tr td.quantity').append('<span>text to append</span>');
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
<tbody>
<tr>
<td class="name"><a>text which triggers append</a></td>
<td class="quantity">quantity</td>
</tr>
<tr>
<td class="name"><a>other text</a></td>
<td class="quantity">other quantity</td>
</tr>
</tbody>