Reputation: 3253
I am trying to change the html in a page with jQuery. While it works in Firefox, it won't in chrome. What can I do to fix this?
Eg.
$('#test').html(<p>hi</p>);
will change the text fine, but if I had other html in the file and am overriding it with this, the old text is still displayed in chrome. Could this be a caching issue? How can I fix it?
Upvotes: 1
Views: 2352
Reputation: 110
if you want to replace text of your id #test then use
$('#test').html("<p>hi</p>");
wanna append more add <p>hi</p>
tag in test id use
$('#test').append("<p>hi</p>");
Upvotes: 0
Reputation: 15742
Use ,
$('#test').html("<p>hi</p>"); //.html() accepts quoted [.html("value")] value.
I think you want to appen to #test
,so use .append()
instead of .html()
.
And if want to overwrite the contents use .html()
.
$('#test').html("<p>hi</p>"); //will override content of test.
$('#test').append("<p>hi</p>"); //will append <p>hi</p> to test.
Some thing interesting for you,
$('#test').html(value) is equivalent to $('#test').empty().append(value).
Upvotes: 2
Reputation: 8771
html()
accepts a string. So you need to encapsulate those characters in quotes.
$('#test').html("<p>hi</p>");
Upvotes: 1