Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using HTML in a jQuery string

I'm not experienced with JS, so please excuse the presumably very beginner question.

I have this line:

$el.text(type + "|");

I need to wrap the "|" in span tags such as '<span class="">|</span>' though when I do so it simply prints out the tags as text as opposed to embedding them as HTML wraps.

How do I go about doing this?

like image 520
John Long Avatar asked Sep 27 '26 04:09

John Long


1 Answers

Use .html() to print out HTML content, text prints out plain text.

$el.html(type + "<span class=''>|</span>");

or

$el.html(type).append($('<span/>',{text : '|'}));
like image 73
Shaunak D Avatar answered Sep 28 '26 17:09

Shaunak D