Question

Okay here is what i have:

<script type="text/javascript">
    var where = document.getElementById("info")
    var texts = false;
    function clear() {
        where.innerHTML = "";
    };

    function dostuff(what) {

            if(where.style.value === ""){
    var comm = document.createTextNode(what);
    where.appendChild(comm);
}else {
    clear();
}

    };
</script>

the id "info" is a div

this is basically a vertical navigation bar that shows tooltips in a div under the buttons when you hover over them.

So I want to first check if the div has no value then if it doesn't then it will append text into it, else it will clear the text but i also want it to append the text after it clears. I'm not sure how to do this and help would be appreciated. thanks

Was it helpful?

Solution

Since you want to clear the item anyways and put your new text in, why even bothering with the conditional? You could just as easily do:

function dostuff(what) {
    where.innerHTML = what;
};

Working example

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top