Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What does $(document.body) mean in javascript?

Tags:

javascript

What does it mean?

like image 958
Himmators Avatar asked Dec 07 '22 00:12

Himmators


1 Answers

The document.body in javascript is a direct reference to the DOM element representing the <body> portion of the page.

The $() part depends on how it is used. $ could be a variable name, and () after a variable or property name attempts to call a function stored in that variable or property.

So if you have:

var $ = function() { alert('howdy'); };

Then this:

$();

...will call that function, and trigger the alert.

Functions can accept arguments, so you could modify the function above to accept the document.body element as an argument, and alert() its innerHTML (for example);

  // alerts the innerHTML of the element it receives
var $ = function( elem ) { alert( elem.innerHTML ); }; 

$( document.body ); // Passes the element when calling the $ function
like image 170
user113716 Avatar answered Dec 24 '22 14:12

user113716