I have an html list something like this:
<li id="tag">red</li>
<li id="tag">yellow</li>
<li id="tag">blue</li>
How can I get the content of these li tags using jQuery?
For example;
$tags = red, yellow, blue
2020-04-22 04:52发布
I have an html list something like this:
<li id="tag">red</li>
<li id="tag">yellow</li>
<li id="tag">blue</li>
How can I get the content of these li tags using jQuery?
For example;
$tags = red, yellow, blue
First, you should change your
id="tag"
toclass="tag"
, as you can't have multiple elements with the same id.You can build an array of the values:
Or as others have pointed out, you can use map:
Here, have a fiddle: http://jsfiddle.net/KTted/2/
You can use jQuery.map()
Live Demo