Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Javascript equivalent to $('body')

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

like image 717
Hugh Rawlinson Avatar asked Jul 25 '13 09:07

Hugh Rawlinson


People also ask

How to append HTML to the body using JavaScript?

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.

What is type conversion in JavaScript?

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.

How to convert a boolean value to a string 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.

How to convert strings to numbers in JavaScript?

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.


1 Answers

Yes, it is document.body

 var contents = document.body.innerHTML;
like image 80
mohkhan Avatar answered Oct 25 '22 14:10

mohkhan