PLATFORM
  • Tails

    Create websites with TailwindCSS

  • Wave

    Start building the next great SAAS

  • Pines

    Alpine & Tailwind UI Library

  • Auth

    Plug'n Play Authentication for Laravel

  • Designer comingsoon

    Create website designs with AI

  • DevBlog comingsoon

    Blog platform for developers

  • Static

    Build a simple static website

  • SaaS Adventure

    21-day program to build a SAAS

Javascript Get the Body Element

<script>   
    let body = document.body;
</script>

Getting the body of the document using javascript is very simple:

<script>   
    let body = document.body;
</script>

that will give you the Body element. You may also get it another way by running:

<script>

    let body = document.getElementsByTagName('body')[0];

</script>
```

However, if you use the second method you should either put the javascript at the end of the document or you'll need to load it inside of a `window.load` function like so:

```
<script>window.onload = function get_body() {
        let body = document.getElementsByTagName('body')[0];
    }

</script>

The easiest way is to call it directly from the document using document.body

BETA Snippet explanation automatically generated by OpenAI:

No explanation generated yet.

Snippet By Dev Dojo

·

Created June 12th, 2021

·

Report Snippet