i have a div,
<div id="product-details">
<li>lorem,ispum</li>
<li>doler,emit</li>
<li>emit,doler</li>
</div>
I want to extract only the content between "li" into three variable. how it possible using jquery
The best method would be to extract the text into an array. To do this you can use a combination of map()
and text()
. Try this:
var liText = $('#product-details li').map(function() {
return $(this).text();
}).get();
You can then retrieve the text from this array as you normally would, either via a loop, or direct access by index:
console.log(liText[1]); // = doler,emit
` element.