Achieve the World’s Most Prestigious Certifications and Unlock Top-Paying Careers! Get Certified in the Industry’s Leading Programs Today.
🚀 DevOps Certified Professional 🚀 SRE Certified Professional 🚀 DevSecOps Certified Professional 🚀 MLOps Certified Professional
📅 Starting: 1st of Every Month 🤝 +91 8409492687 | 🤝 +1 (469) 756-6329 🔍 Contact@DevOpsSchool.com

Upgrade & Secure Your Future with DevOps, SRE, DevSecOps, MLOps!

We spend hours on Instagram and YouTube and waste money on coffee and fast food, but won’t spend 30 minutes a day learning skills to boost our careers.
Master in DevOps, SRE, DevSecOps & MLOps!

Learn from Guru Rajesh Kumar and double your salary in just one year.



Get Started Now!

JavaScript DOM(Document Object Model)

DOM is such a technology with the help of which we can completely control any html document with JavaScript.

With the help of DOM we can access and change any tag, id, class or any attribute, even we can change any CSS style from DOM.

METHODS

getElementById()

getElementsByclassName()

getElementsByTagsName()

querySelector()

querySelectorALL()

first have to make HTML, CSS and JavaScript files(HTML, CSS source code down there )

HTML source code:-

https://gist.github.com/AvinashKumar33/7d3f01e81b510279354e5a86e5fdec04

CSS source code:-

*{
        margin: 0;
        padding: 0;

}
body{
    font-family: Arial, Helvetica, sans-serif;
}
header{
    background-color: rgb(11, 241, 187);
    color: white;
    padding: 15px 0px 20px 40px;
}
h2#header-title{
    padding: 10px 0px;

}
div#content{
    padding: 15px 0px 0px 45px;
}
div#content >h2{
    border-bottom: 5px solid rgb(37, 37, 33);
    padding: 0px 20px 10px 5px;
    display: inline-block;
    width: 50%;
}
li.list-item{
    border-bottom: 1px solid grey;
    padding: 10px 0px;
}
form{
    padding-top: 20px;

}
form > input, button{
    padding: 5px;
}

OUTPUT

Example: Here we change (Name with ‘Earth‘) by the help of getElementById().

var headerTitle = 
document.getElementById('header-title');

headerTitle.textContent = 'Earth'; 

Example: Here we do styling with the help of JavaScript

var headerTitle = 
document.getElementById('header-title');

headerTitle.textContent = 'Computer courses';
var header = document.getElementById('header');

header.style.borderBottom = '10px solid #000';

OUTPUT

Example: Here we doing changes in list-item value by help of getElementsByclassName()

var items = 
document.getElementsByClassName('list-item');

items[1].textContent = 'Russia';

OUTPUT

Example: Here we using .getElementsByClassName() and changing in style in particular class element.

var items = 
document.getElementsByClassName('list-item');

items[1].textContent = 'Russia';
items[2].textContent = 'Indonesia';
items[3].textContent = 'Egypt';
items[2].style.fontWeight = 'bold';
items[3].style.color = 'red';
items[2].style.backgroundColor = 'yellow'; 

Example: Here we using .querySelector to change color of ID tagline.

var headline = document.querySelector('#tagline');
headline.style.color = 'red';

Related Posts

How We Fixed “sonar-scanner: command not found” and Successfully Analyzed Our Project with SonarQube

Running static code analysis with SonarQube is essential for maintaining clean, quality code. Recently, while working on our Laravel microservice project mhn-doctors-ms, we hit a common yet…

Is SonarQube Community free Edition Good for Laravel Projects?

When working on web development projects using Laravel, JavaScript, and jQuery, maintaining code quality becomes just as important as building features. That’s where tools like SonarQube come…

Laravel Throttle Middleware: How to Increase API Rate Limit Safely and for 429 Too Many Requests

If you’re working with Laravel APIs, you might have encountered this default throttle setting: This line lives in your app/Http/Kernel.php file and controls how many requests a…

Fixing MySQL Error: Incorrect Definition of mysql.column_stats Table

The Problem While working on your MySQL server, you might come across this error in your error log: This error usually shows up after an upgrade or…

Fixing Laravel Migration Error: “Unknown Collation: utf8mb4_0900_ai_ci”

While working with Laravel and MySQL, you might run into an error during migrations like this one: Why This Happens The collation utf8mb4_0900_ai_ci is introduced in MySQL…

Why Dental Surgery Is Good and Important

Dental health plays a vital role in our overall well-being, yet it’s often overlooked until problems become serious. Dental surgery is a powerful solution that not only…

0 0 votes
Article Rating
Subscribe
Notify of
guest


0 Comments
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x