jQuery is not finding elements

后端 未结 4 1104
伪装坚强ぢ
伪装坚强ぢ 2021-01-21 06:06

jQuery is not finding any elements. alert($(\"#testbutton\").length); displays 0 every time.

Am I doing something wrong?

My JS / jQuery cod

4条回答
  •  猫巷女王i
    2021-01-21 06:25

    Call it on document ready as you can see here: http://jsfiddle.net/SwQUH/

    $(document).ready(function() {
      alert($("#testbutton").length);
    });
    

    If you just call it like that, the DOM isn't 'ready' and the HTML element doesnt yet exist.

提交回复
热议问题