I have 2 tables with same class elements like:
<table class="myTbl">
<thead>
<tr>
<th>A</th>
<th>B</th>
</tr>
</thead>
<tbody>
<tr>
<td>1</td>
<td>2</td>
</tr>
</tbody>
<table class="myTbl">
<thead>
<tr>
<th>C</th>
<th>D</th>
</tr>
</thead>
<tbody>
<tr>
<td>3</td>
<td>4</td>
</tr>
</tbody>
When I add jquery function like
$(function(){ $('.myTbl tbody').function() })
I want the function only run in specific table like table 1 , but I’m having duplicate classes. How to do it?
And I cant affect the html table like change class or add id,… cause It’s exported from other, only js or jquery to do it.
I tried $('.myTbl tbody:nth-child(1)')
not working.
2
Answers
you can do that with adding .eq(0) to your code
You can add one more class to the element that you want to select, or you can also select by index of all selected elements.