Anonymous12345 Anonymous12345 - 3 months ago 5x
HTML Question

why won't this style.display work?

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

css style.

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

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


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

I haven't set it with css either!


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

var el = document.getElementById("annonsera_price");

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 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.