I have been trying to create a textnode that will expand and contract onclick, however it refuses to work in google chrome and displays [object Text] in firefox, where am I going wrong?
http://jsfiddle.net/jonSnow70/uf1bbk5q/
window.onload = function ()
document.getElementById("myBtn").addEventListener("click",
textchange);
function textchange() {
var status = "less";
var text = document.createTextNode('Mmm ... something');
if (status == "less") {
document.getElementById("textArea").innerHTML = text;
status = "more";
} else if (status == "more") {
document.getElementById("textArea").innerHTML = "";
status = "less"
}
}
Hmm, not sure why Chrome doesn't like
.innerHTML =
, but I tried replacing it with.appendChild()
and it works. Try this:By the way, declare
var status="less"
outside of yourtextchange()
function. That way it will be global and not get reset everytime you click#myBtn
.