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

jquery - Javascript equivalent to $('body') - Stack Overflow

programmeradmin4浏览0评论

Is there a javascript equivalent to the jQuery $('body'), as in the following code? I want to get it running without requiring jQuery.

var content = $('body').html();
var ments = content.match(/<!--.*?-->/g);
if(ments!=null|ments!=undefined){
    for (var x = 0; x < ments.length;x++){
        console.log(ments[x]);
    }
}
else{
    console.log('No Comments');
}

Thanks

Is there a javascript equivalent to the jQuery $('body'), as in the following code? I want to get it running without requiring jQuery.

var content = $('body').html();
var ments = content.match(/<!--.*?-->/g);
if(ments!=null|ments!=undefined){
    for (var x = 0; x < ments.length;x++){
        console.log(ments[x]);
    }
}
else{
    console.log('No Comments');
}

Thanks

https://gist.github./hughrawlinson/6078055

Share Improve this question asked Jul 25, 2013 at 9:04 Hugh RawlinsonHugh Rawlinson 9999 silver badges29 bronze badges 1
  • 4 I think document.body ? – Praveen Commented Jul 25, 2013 at 9:05
Add a ment  | 

3 Answers 3

Reset to default 9

Yes, it is document.body

 var contents = document.body.innerHTML;

As I already mentioned in ments.

var contents = document.body.innerHTML;

or

var contents = document.getElementsByTagName('body').innerHTML; 

You can replace $('body').html() with:

document.body.innerHTML
发布评论

评论列表(0)

  1. 暂无评论