Anonymous12345 Anonymous12345 - 4 months ago 13
HTML Question

why won't this style.display work?

Why won't this work? It should check the element for

display
css style.

if (byId("annonsera_price").style.display=='inline' || byId("annonsera_price").style.display=='block'){
alert ("Hello");
}

function byId(x){
return document.getElementById(x);
}


update2:

<input style="width:100px;" type="text" name="annonsera_price" id="annonsera_price">


I haven't set it with css either!

Answer

First try alerting just the style.display and see what it contains:

var el = document.getElementById("annonsera_price");
alert(el.style.display);

style only references what is in the style attribute (or set through JS on the style property). It's possible that the display is set through the class, and therefore el.style.display won't show anything.

[Update]:Given the update, the reason no alert happens is because style.display will be "", not "inline" or "block". It won't be "inline" or "block" until you set it to something, either in the style attribute or by setting .style.display.