Gašper Sladič
Gašper Sladič

Reputation: 897

JQuery append filters out html like tags?

I would like to append below line of text to the select html tag using JQuery:

"<option selected=true value="-1"><new></option>"

The problem is in <new>. This substring is filtered out completely by append function. I know this is not legal html tag, and probably it filters it just of this reason. Can I force JQuery somehow to interpret <new> as substring? Because <new> is not meant as html tag, but only to point out to the user that this is not the value in the list, but a selection to make a new entry on the list.

Upvotes: 0

Views: 212

Answers (3)

Aravind S
Aravind S

Reputation: 2395

try this

$('<option/>').attr("value","-1").text("<new>").appendTo("select");

Thanks !

Upvotes: 1

Vijay Arun
Vijay Arun

Reputation: 414

$('#test').append($('<option>').attr('value', -1).text('<new>')[0]);

Upvotes: 1

Sarah Aziziyan
Sarah Aziziyan

Reputation: 516

take a look at this post : How to display HTML tags as plain text

it shows you how to print special characters like < and > in between your code.

you should replace < by &lt; and > by &gt;

Upvotes: 2

Related Questions