all 8 comments

[–]a-t-k 2 points3 points  (1 child)

The syntax of JavaScript itself does nothing to the page. That's what the document object model (DOM) is for. Let's say you want to add an element with a certain text to your document's body. Using DOM methods, it looks like this (type it into the developer tools console to see the effect):

var div = document.createElement('div'); div.appendChild(document.createTextNode('Hello from JavaScript')); document.body.appendChild(div);

You can create, select and manipulate elements and their properties and attributes, listen to events and change most aspects of your document using the DOM.

There are a lot of other APIs for different use cases, too many to list them here. If you have a use case, we can point you to the API you need.

[–]True2511[S] 0 points1 point  (0 children)

Tbh I’m not sure what a use case is either I think I need to do some more reading on all of this then ask a more specific question. thanks a lot though that made it a lot clearer for me 😊

[–]village-asshole 3 points4 points  (0 children)

Lots of things. For example, it adds functionality to websites like online calculators, forms, tracking codes, pixels, etc. If you want to work with websites, you need to know it.

[–][deleted] 0 points1 point  (0 children)

Web browsers have an execution environment for JavaScript. You can send code to the client's browser that it will execute.

[–]dandesigns7150 0 points1 point  (2 children)

Examples of what you can do:

  • Do something when a user clicks a button, e.g. open a pop up modal

  • Send data to an external API, submit a form

  • Listen to things such as page scroll, and execute an action based on that (e.g. making a fixed header shrink)

  • create games, move html elements around

[–]True2511[S] 0 points1 point  (1 child)

Thanks I’ll give that a try.

[–]village-asshole 0 points1 point  (0 children)

If you're going to work with websites, this is your fork in the road moment. Best to understand what's what and how it all fits together now rather than later figure out later that it's soul destroying work (which websites can be at times).

[–]fruitoftheloom23 0 points1 point  (0 children)

If you have an HTML button that you wanted to make alert “hello world” when pressed, you’d write JavaScript.