Thought this would show the display property, but it dosen’t:
alert(document.getElementById(“thisDiv”).style.display);
What am I doing wrong?
Thanks
niche
Thought this would show the display property, but it dosen’t:
alert(document.getElementById(“thisDiv”).style.display);
What am I doing wrong?
Thanks
niche
What do you get if you do this?
console.log(document.getElementById("thisDiv").style.display);
same thing (nothing)
console.log("Hello World");
Plainly displays
have you actually SET a display style to the element? Elements without a display style might inherit from parents (or the document default), but wont report a value unless it has been explicitly set.
set with this function:
function myFunction() {
var x = document.getElementById("thisDiv");
if (x.style.display === "none") {
x.style.display = "block";
} else {
x.style.display = "none";
}
}
and (forgive me for being pedantic, but basic checks…) you have actually CALLED this function before trying to alert the value, right?
m_hutley, problem solved.
You can never be too specific when it comes to code!
function myFunction() {
var x = document.getElementById("myDIV");
if (x.style.display === "none") {
x.style.display = "block";
} else {
x.style.display = "none";
}
alert(document.getElementById("myDIV").style.display);
}
This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.