1
Guys, I have the following ajax call:
$(".sec-tags").html(res.data.tags);
It is returning the server call, however the call is coming as follows:
tags: "coelho,teste,gato"
Everything is coming within a single string separated by commas. How do I separate these words and place each one within an html tag:
<span class="tags">minha tag aqui</span>
My HTML is:
<div class="col-md-6">
<div class="sec-tags">
<span class="tags"></span>
</div>
</div>
Yes, this is only part of the result of an object. I did: var string = $(".tags"). html(res.data.tags); var resTags = string.split(","); Document.getElementByClassName("tags"). innerHTML = resTags; but no result.
– Hitch Leonardo
@Hitchleonardo you need one
for
or theeach()
to iterate the elements, thesplit()
return an array, you can use theappend()
to create a<span>
for each element.– rray
@William I thought about it, but on my console there’s an alert: "string.split is not a Function "
– Hitch Leonardo