I’m trying to get some elements in my page using the DOM: $('ul li').text()
And after that (or maybe during that) I would like to add a comma. In some cases the text that I’m getting has white spaces and other characters.
As a result I would love to get an array like this for example ["first text", "second element", "third"]
What would be the easier way to do that using javascript functions or jQuery?
Thanks in advance for your help.
If I’ve understood your question correctly, you want to put the text of each
liin your selector into an array. If so, try this:Example fiddle