最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Check HTML page for particular table ID and element using jQuery - Stack Overflow

programmeradmin1浏览0评论

Does jQuery have a method of determining if a particular table exists in a HTML document and alert(); me whether it does or does not exist?

The particular tables' existence I'm looking for in the document is:

<table id="main_table"

Does jQuery have a method of determining if a particular table exists in a HTML document and alert(); me whether it does or does not exist?

The particular tables' existence I'm looking for in the document is:

<table id="main_table"
Share edited Nov 4, 2017 at 23:06 Brian Tompsett - 汤莱恩 5,89372 gold badges61 silver badges133 bronze badges asked May 22, 2012 at 11:04 derek8derek8 2691 gold badge5 silver badges11 bronze badges
Add a ment  | 

3 Answers 3

Reset to default 8
$(function() {
    // after dom ready

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

})

at domready event just check

$(function() {
    if ($('#main_table').length) { ... /* element exists */ }

    /** 
     * or - without passing again through jQuery function -
     * if (document.getElementById('main_table')) { ... }
     */
});
$(document).ready(function() {
     $("#check").click(function() {
         if($('table#main_table').length){
          alert('Table Exists');
        }
    });
});

Example: http://jsfiddle/ipsjolly/3nVrZ/2/

发布评论

评论列表(0)

  1. 暂无评论