You can use (or ) along with the method. eq() :eq() each()
// iterate ove li elements
$('#first li').each(function(i) {
console.log(
// get text from li
$(this).text(),
// get li from second based on index and get text
$('#second li').eq(i).text(), // you can also use `$('#second li:eq(' + i + ')')`
// get li from third based on index and get text
$('#third li').eq(i).text());
});
$('#first li').each(function(i) {
console.log(
$(this).text(),
$('#second li').eq(i).text(),
$('#third li').eq(i).text());
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<ul id='first'>
<li>1</li>
<li>2</li>
<li>3</li>
<li>4</li>
</ul>
<ul id='second'>
<li>5</li>
<li>6</li>
<li>7</li>
<li>8</li>
</ul>
<ul id='third'>
<li>9</li>
<li>10</li>
<li>11</li>
<li>12</li>
</ul>
Run code
Or you can use the callback method instead . text() each()
// iterate over li elements where first argument holds index
// and second argument holds the text content
$('#first li').text(function(i, v) {
console.log(
v,
// get li from second based on index and get text
$('#second li').eq(i).text(),
// get li from third based on index and get text
$('#third li').eq(i).text());
});
$('#first li').text(function(i, text) {
console.log(
text,
$('#second li').eq(i).text(),
$('#third li').eq(i).text());
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<ul id='first'>
<li>1</li>
<li>2</li>
<li>3</li>
<li>4</li>
</ul>
<ul id='second'>
<li>5</li>
<li>6</li>
<li>7</li>
<li>8</li>
</ul>
<ul id='third'>
<li>9</li>
<li>10</li>
<li>11</li>
<li>12</li>
</ul>
Run code source
share