开发者

jQuery: existence of something after it is hidden

In this fiddle http://jsfiddle.net/SySRb/105/, function init(); successfully checks for the existence of an id and thereafter hides two divs on page ready.

function test() is supposed开发者_如何学运维, once you click the .start box, to check whether or not those two hidden divs still exist (in terms of are they available to jquery), and, if they do, show a box called "exist" or, if they don't exist, show "noexist".

function test isn't working.

Note, my interest in creating this fiddle was finding out whether, once an id is hidden using jquery, whether it still "exists" or not. However, even if you tell me the answer to that, I still need to make function test() work.

Can you help me make function test work?


Do this:

$(document).ready(function(){       
    init();  
    test();
});

And it works for me.


jQuery operates on the DOM. Even though you hide a div, it still exists. Therefore, jQuery still has access to it.

The problem with your example is that you never call the function test(). I've cleaned up the code and simplified it some for you: http://jsfiddle.net/SySRb/107/


You're never calling test(), so the click event is never bound to .start. Try this:

$(document).ready(function() {
    init();
    test();
});

http://jsfiddle.net/SySRb/109/

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜