I have a list:
<ul class='class-name'>
<li><p>value1</p></li>
<li></li>
<li><p>value2</p></li>
<li><p>value3</p></li>
</ul>
I want to get value1,value2,value3. I’m using:
$('ul.class-name > li > p').text();
But I’m getting value1value2value3.
Can anyone tell me how to get a comma separated value?
You could try this…
jsFiddle.
This gets all the
pelements, iterates over them replacing their references with their text, then gets a real array from the jQuery object, and joins them withjoin()(the,is the default separator).