is there any way in jquery to check if any HTML tag present inside TD
Example :
<td>
<small></small>
<pre></pre>
</td>
CodePudding user response:
Using children()
to select the children element(all directly sub element) and using tagName
to get the element name.
$("td").children().each((i,e) => {
console.log(e.tagName)
});
table, tr, td {
border: 1px solid black;
border-collapse: collapse;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<table>
<tbody>
<tr>
<td>
<small>AA</small>
<pre>BB</pre>
</td>
<td>
<span>Test1</span>
<ul>
<li>11</li>
<li>12</li>
</ul>
</td>
</tr>
</tbody>
</table>