Javascript Variables: Dom and Event Fundamentals - Cheat Sheet
Javascript Variables: Dom and Event Fundamentals - Cheat Sheet
1. JavaScript Variables
Variables are like containers for storing values. We can create a variable using the
let keyword.
JAVASCRIPT
1 let message;
= ).
JAVASCRIPT
JAVASCRIPT
1 let message;
2 message = 'Hello Rahul';
Try out changing the JavaScript Variables and their Values in the below Code Playground and check the
output in the console.
1 <!DOCTYPE html>
2 <html>
3 <head></head>
4 <body>
5 Your HTML code goes here. Write JavaScript
6 </body>
7 </html>
https://learning.ccbp.in/course?c_id=5e93210e-f183-433d-a12d-79d81deb01be&t_id=64c6b29b-1c30-4fc9-b45c-2ec92b266c14&s_id=5ada9e21-… 1/4
7/31/24, 6:47 PM Revolutionizing the Job Market | NxtWave
Note
Printing a variable without assigning a value will give the output undefined .
The DOM is the structured representation of the HTML document created by the browser. It allows JavaScript
to manipulate, structure, and style your website.
HTML
1 <!DOCTYPE html>
2 <html>
3 <head></head>
4 <body>
5 <h1>Web Technologies</h1>
6 <button>Change Heading</button>
7 </body>
8 </html>
It is the entry point of the DOM. For accessing any HTML Element, you should always start with accessing the
document object first.
The DOM tree represents an HTML document as nodes. Each node is referred to as an Object.
https://learning.ccbp.in/course?c_id=5e93210e-f183-433d-a12d-79d81deb01be&t_id=64c6b29b-1c30-4fc9-b45c-2ec92b266c14&s_id=5ada9e21-… 2/4
7/31/24, 6:47 PM Revolutionizing the Job Market | NxtWave
2.3 Methods
2.3.1 getElementById
The
getElementById() method helps to select the HTML Element with a specific ID.
JAVASCRIPT
1 console.log(document.getElementById("headingElement"))
2.4 Properties
2.4.1 textContent
textContent Property.
2.4.2 style
The
style property is used to get or set a specific style of an HTML Element using different CSS properties.
Use Camel Case naming convention (starting letter of each word should be in the upper case except for the
first word) for naming the Style Object Properties.
For example,
2.5 Events
Events are the actions by which the user or browser interacts with the HTML Elements. Actions can be
anything like clicking a button, pressing keyboard keys, scrolling the page, etc.
https://learning.ccbp.in/course?c_id=5e93210e-f183-433d-a12d-79d81deb01be&t_id=64c6b29b-1c30-4fc9-b45c-2ec92b266c14&s_id=5ada9e21-… 3/4
7/31/24, 6:47 PM Revolutionizing the Job Market | NxtWave
The
onclick event occurs when the user clicks on an HTML Element. We will give the name of the function as a
value for the HTML onclick attribute.
HTML
1 <body>
2 <h1 id="headingElement">Web Technologies</h1>
3 <button onclick="manipulateStyles()">Change Heading</button>
4 </body>
JAVASCRIPT
1 function manipulateStyles() {
2 document.getElementById("headingElement").textContent = "4.O Technologies";
3 document.getElementById("headingElement").style.color = "blue";
4 }
https://learning.ccbp.in/course?c_id=5e93210e-f183-433d-a12d-79d81deb01be&t_id=64c6b29b-1c30-4fc9-b45c-2ec92b266c14&s_id=5ada9e21-… 4/4