【JQuery】判断dom是否存在(undefined)

<div id=”MyDiv”></div>

判断ID为MyDiv的div是否存在:

js代码:

$(document).ready(function () {

if (jQuery (“#MyDiv” ).length > 0 ) {

alert(“存在”);

} else {

alert(“不存在”);

}

});

Author: jhonse

Jhonse技术博客: http://blog.jhonse.com

Leave a Reply

Your email address will not be published. Required fields are marked *