I want to load contents of a DIV dynamically in javascript.I used this code
var strHtml="<h3>Test</h3>";
var div = $("#divPrice");
div.innerHTML=strHtml
This works in IE. But not in firefox.Whats the alternative of this which works on all browsers ?
I want to load contents of a DIV dynamically in javascript.I used this code
var strHtml="<h3>Test</h3>";
var div = $("#divPrice");
div.innerHTML=strHtml
This works in IE. But not in firefox.Whats the alternative of this which works on all browsers ?
Share Improve this question edited Jun 7, 2009 at 9:50 Paolo Bergantino 488k82 gold badges521 silver badges437 bronze badges asked Jun 7, 2009 at 9:44 ShyjuShyju 219k106 gold badges419 silver badges498 bronze badges 1- 4 I'm surprised this works in IE... It certainly shouldn't – James Commented Jun 7, 2009 at 10:49
4 Answers
Reset to default 8Try it this way:
var strHtml="<h3>Test</h3>";
$("#divPrice").html(strHtml);
It looks like you are using jquery, so you can use:
var strHtml="<h3>Test</h3>";
var div = $("#divPrice");
div.html(strHtml);
I take it you're using a JavaScript Framework based on $()
. Looking at your other questions, it looks like you're using jQuery, in which case you can do
$("#divPrice").html(strHtml);
Just for reference, jQuery's html()
mand does the following
jQuery.fn = jQuery.prototype = {
html: function( value ) {
return value === undefined ?
(this[0] ?
this[0].innerHTML.replace(/ jQuery\d+="(?:\d+|null)"/g, "") :
null) :
this.empty().append( value );
}
}
I assume you use pure javascript, not jquery.
var div = $("#divPrice");
should be
var div = document.getElementById("divPrice");
Others are fine.