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
3 Answers
Reset to default 9Yes, 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