postImage

Basics of Javascript

blogImage

By Emmanuel Chinonso

Web Developer

Last updated: 5 May 2024

Basics of JavaScript

Contrast Bootstrap UI Kit

We'll look at some examples of what JavaScript can accomplish. If you don't understand the code, don't worry. The purpose of this chapter is to show you what JavaScript can do.

JavaScript Can Change HTML Content

getElementById is one of numerous JavaScript HTML methods (). The following example "finds" an HTML element (with id="demo") and replaces its content (innerHTML) with "Hello JavaScript":

Code:

js
document.getElementById('demo').innerHTML = 'Hello JavaScript';

Or

js
document.getElementById('demo').innerHTML = 'Hello JavaScript';

JavaScript can take both single and double quotes.

JavaScript Can Change HTML Attribute Values In this example, JavaScript modifies the value of a "src" attribute of an <img> tag Images

JavaScript Can Change HTML Styles (CSS) Modifying an HTML element's style is similar to changing an HTML attribute: Code:

js
document.getElementById('demo').style.fontSize = '35px';

JavaScript Can Hide HTML Elements Changing the display style can be used to hide HTML elements:

Code:

js
<p id="example-4">I will disappear!</p>
<button type="button" onclick="document.getElementById('example-4').style.display='none'">Click Me!</button>

JavaScript Can Show HTML Elements

Changing the display style can also be used to reveal hidden HTML elements:

Code:

js
document.getElementById('demo').style.display = 'block';

Contrast Bootstrap UI Kit

Build modern projects using Bootstrap 5 and Contrast

Trying to create components and pages for a web app or website from scratch while maintaining a modern User interface can be very tedious. This is why we created Contrast, to help drastically reduce the amount of time we spend doing that. so we can focus on building some other aspects of the project.

Contrast Bootstrap PRO consists of a Premium UI Kit Library featuring over 10000+ component variants. Which even comes bundled together with its own admin template comprising of 5 admin dashboards and 23+ additional admin and multipurpose pages for building almost any type of website or web app.
See a demo and learn more about Contrast Bootstrap Pro by clicking here.

Related Posts