JAVASCRIPT FOR BEGINNERS

JAVASCRIPT FOR BEGINNERS

The HTML <script> Tag

The HTML <script> tag is used to define a client-side script (JavaScript).

The <script> element either contains script statements, or it points to an external script file through the src attribute.

Common uses for JavaScript are image manipulation, form validation, and dynamic changes of content.

To select an HTML element, JavaScript most often uses the document.getElementById() method.

This JavaScript example writes Hello JavaScript! into an HTML element with id=demo:

Example:

<script>document.getElementById(boma).innerHTML = Hello World!;</script>

style <script>

READ ALSO » JS101: A Beginners Guide To Javascript

The style property returns a CSS Style Declaration object, which represents an element's style attribute.

The style property is used to get or set a specific style of an element using different CSS properties.

Example 1:

<script>document.getElementById(boma).style.color = red;</script>

Window alert() <script>

The alert() method displays an alert box with a specified message and an OK button.

An alert box is often used if you want to make sure information comes through to the user.

Note: The alert box takes the focus away from the current window, and forces the browser to read the message. Do not overuse this method, as it prevents the user from accessing other parts of the page until the box is closed.

Example 2:

<script>window.alert(Welcome To This Page!!);</script>

JavaScript Functions

READ ALSO » Introduction To JavaScript Programming Language

A JavaScript function is a block of code designed to perform a particular task.

A JavaScript function is executed when something invokes it (calls it).

Example:

<script>function myFunction() { document.getElementById(tbr).innerHTML = WELCOME TO THIS PAGE;}</script>

JavaScript Date

By default, JavaScript will use the browser's time zone and display a date as a full text string:

Mon Oct 18 2021 19:57:30 GMT+0100 (West Africa Standard Time)

You will learn much more about how to display dates, later in this tutorial.

THANKS FOR READING AND DON'T FORGET TO SHARE......