tags:

views:

4367

answers:

3

i am trying to insert a chuck of html into a div. i want to see if plain javascript way is faster than using jquery. unfortunately, i forgot how to do it the 'old' way :P

var test2 = function(){
    var cb = function(html){
        var t1 = document.getElementById("test2");
        var d = document.createElement("div");
        d.id ="oiio"
        d.innerHtml = html;
        t1.appendChild(d);
        console.timeEnd("load data with javascript")
    }
    console.time("load data with javascript");
    $.get("test1.html", cb);
}

what am i doing wrong here guys? also, there is a live test of this here: http://programmingdrunk.com/playground/

+6  A: 

isn't it innerHTML?

Jason
inner html didnt do it. i made another test on the above linked testpage. not enough room to link that code into here.
mkoryak
case sensitive.var d = document.getElementById("mydiv");d.innerHTML = "<b>foo!</b>"; //HTML - all caps
Jason
if you are really programming drunk this type of error is not uncommon :)
Jason
i am programming drunk, and you are correct. i was sticking some html in an exan-doh
mkoryak
+1  A: 

I think this is what you want:

document.getElementById('tag-id').innerHTML = '<ol><li>html data</li></ol>';

Keep in mind that innerHTML is not accessable for all types of tags when using IE. (table elements for example)

Nathan Reed
A: 

I know this is a fairly old post. I'm having a similar issue. I am trying to add insert an image gallery into a div using javascript. I used:

document.getElementById('divId').innerHTML = 'myHTML';

Unfortunately, IE doesn't recognize it. but all other browser do. Is there another way I can go about insert html into that div?

Amp town