Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get innerHTML from a div?

I need to save the innerHTML of a div and store it in a cookie. Here is my basic code.

//The div-saving function
function addStatus(sName){
    getElement("bottomDiv").innerHTML += sName + "<br>";
    document.cookie="status=" + sName + "<br>";
}

//The button clicking function
function clk(){
    num++;
    document.cookie = "num=" + num;
    switch(num){
        case 25:
            addStatus("25: Alright! Let the games begin!");
        break;
        case 50:
            addStatus("50: Woah! Getting into the high numbers!");
        break;
    }
}

What ends up happening is only the last achieved status gets saved. I need to know how to get the innerHTML of the div instead. Thank you.

like image 425
ZeroByter Avatar asked Apr 21 '14 04:04

ZeroByter


2 Answers

Try this..

 var div= document.getElementById("bottomDiv").innerHTML;
like image 83
Jameem Avatar answered Oct 09 '22 10:10

Jameem


var holder = document.getElementById("bottomDiv").innerHTML;

The above will get the innerHTML value and assign it to the variable. Also there is no built in function getElement , you can use getElementById, there are other variations as well.

like image 1
lwalden Avatar answered Oct 09 '22 08:10

lwalden