views:

449

answers:

4

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 ?

+1  A: 

I assume you use pure javascript, not jquery.

var div = $("#divPrice");

should be

var div = document.getElementById("divPrice");

Others are fine.

Billy
+5  A: 

It looks like you are using jquery, so you can use:

 var strHtml="<h3>Test</h3>";
 var div = $("#divPrice");  
 div.html(strHtml);
Artem Barger
+6  A: 

Try it this way:

var strHtml="<h3>Test</h3>";
$("#divPrice").html(strHtml);
Jose Basilio
+1, it helped me out
marcgg
+5  A: 

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() command 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 );
        }
    }
Russ Cam
Thanks ALL.IT worked
Shyju