Amit Kumar Pandit
Amit Kumar Pandit

Reputation: 93

Appending a new input textbox DOM to HTML body using jQuery

I am trying to append an input box at runtime with value as "&#0" using jQuery, but the value gets displayed as �. The below code works fine in Internet Explorer.

$('body').html($('<input id="myInput" type="text" value="&#0;"/>'));

Upvotes: 2

Views: 627

Answers (1)

Arun P Johny
Arun P Johny

Reputation: 388316

I think when you are using .html() the content is considered to be HTML encoded, so try

$('body').html($('<input />', {
    id: "myInput",
    type: "text",
    value: "�"
}));
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>

Demo: Fiddle (it looks like the code snippet also does the same, so here goes the fiddle.)

Upvotes: 3

Related Questions