开发者

Is it possible to run javascript "onclick" on a thing that has css set to "display: none"?

Just wondering if this was possible using like a s开发者_运维知识库creen reader or a text browser or something weird.

Thanks,

Billmalarky.


Yes. You can invoke the onclick event with element.onclick();


Nope! If it's not there you can't click on it.

However, JavaScript may be disabled on a browser. If your page doesn't work without JavaScript, you need to work on some graceful degradation.

(If I'm not understanding your question correctly and you actually want an element to be clickable and to occupy the same space it normally would, set its opacity to 0 using the various methods, or possibly text-indent to -9999px or something similar.)


No, only when the element is removed, it has 0 height and width.


If you're not wanting the behavior to work until display is updated to 'inline'; then this is a simple matter (with any luck!)

That is, in the code that updates the CSS property:

$('#myDiv').css('display','inline').click(function() {

  alert('div is clicked!');

});

then to negate that:

$('#myDiv').css('display','none').click(function() {

    return false;

});


You could use visibility:hidden

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜