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 comments = content.match(/<!--.*?-->/g);
if(comments!=null|comments!=undefined){
for (var x = 0; x < comments.length;x++){
console.log(comments[x]);
}
}
else{
console.log('No Comments');
}
Thanks
https://gist.github.com/hughrawlinson/6078055
The right way to append HTML to the body using JavaScript. The correct approach is to construct the element using JavaScript’s createElement () method: In the JavaScript example above, we: Created a DIV element using the document.createElement () method.
In programming, type conversion is the process of converting data of one type to another. For example: converting String data to Number. There are two types of type conversion in JavaScript.
The global method String () can convert booleans to strings. The Boolean method toString () does the same. When JavaScript tries to operate on a "wrong" data type, it will try to convert the value to a "right" type.
In JavaScript, explicit type conversions are done using built-in methods. Here are some common methods of explicit conversions. 1. Convert to Number Explicitly To convert numeric strings and boolean values to numbers, you can use Number (). For example, In JavaScript, empty strings and null values return 0.
Yes, it is document.body
var contents = document.body.innerHTML;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With