使用jQuery检查HTML页面中的特定表ID和元素

der*_*ek8 0 html javascript jquery html-table exists

jQuery是否有一种方法来确定HTML文档中alert();是否存在特定的表,以及我是否存在?

我在文档中寻找的特定表的存在是:

<table id="main_table"
Run Code Online (Sandbox Code Playgroud)

the*_*dox 8

$(function() {
    // after dom ready

    if($('table#main_table').length){
      alert('exists');
    }

})
Run Code Online (Sandbox Code Playgroud)