Jquery to cross a div and get information about its range
I have an html page as below:
<div id="test1">
<table>
<tr>
<td><span id="234">ABKO</span></td>
</tr>
<tr>
<td><span id="1234">ABKO2</span></td>
</tr>
<tr>
<td><span id="2634">ABKO3</span></td>
</tr>
</table>
</div>
<div id="test2">
<table>
<tr>
<td><span id="233">ABKOw</span></td>
</tr>
<tr>
<td><span id="1236">ABKOc</span></td>
</tr>
<tr>
<td><span id="2635">ABKOv</span></td>
</tr>
</table>
</div>
How can I get all the information about the gaps between using jQuery? for example, if I consider the first div = test1, then I want all soybeans with their identifier and text in the form div → test1 Span => id 233 && ABKO Span => id 1234 && & ABKO2 Span => id 22634 && ABKO3
+3
2 answers
You can iterate over all elements <span>:
$('div span').each(function(){
var $span = $(this);
var divId = $span.closest('div').attr('id');
var spanId = $span.attr('id');
var spanTxt = $span.text()
// do something with the above
});
Here you can see here.
, span, div ( CSS div span). . Each().
$(this) span. $span, jQuery.
. () , (div). div.
+7