JQuery append filters out html like tags?

213 Views Asked by At

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.

3

There are 3 best solutions below

0
On BEST ANSWER

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;

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

try this

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

Thanks !