If you have any query feel free to chat us!
Happy Coding! Happy Learning!
In "DOM + Modern JS - Class I," we'll explore the Document Object Model (DOM) and how to use modern JavaScript to interact with HTML elements and manipulate the DOM. The DOM is a programming interface for web documents and allows JavaScript to access and modify the content, structure, and style of HTML documents. Let's get started:
Accessing Elements: You can use various methods to access HTML elements in the DOM.
javascriptCopy code
// JavaScript // Using getElementById (returns a single element) let myDiv = document.getElementById("myDiv"); // Using getElementsByClassName (returns a collection of elements) let btns = document.getElementsByClassName("btn"); // Using querySelector (returns the first matching element) let myButton = document.querySelector(".btn"); // Using querySelectorAll (returns all matching elements) let allButtons = document.querySelectorAll(".btn");
htmlCopy code
<!-- HTML --> <div id="myDiv">Hello, DOM!</div> <button class="btn">Click Me</button>
Modifying Elements: You can modify the content and attributes of HTML elements using the DOM.
javascriptCopy code
// JavaScript myDiv.textContent = "Hello, Updated DOM!"; // Modify text content myButton.innerHTML = "Click Me Again"; // Modify HTML content myButton.setAttribute("disabled", true); // Set attribute myDiv.style.color = "red"; // Change CSS styles
Event Handling: You can attach event listeners to HTML elements to respond to user interactions.
javascriptCopy code
// JavaScript myButton.addEventListener("click", function () { console.log("Button clicked!"); }); // Event delegation (attaching event to a parent element) let parentElement = document.getElementById("parent"); parentElement.addEventListener("click", function (event) { if (event.target.classList.contains("btn")) { console.log("Button clicked!"); } });
Creating and Appending Elements: You can create new elements and append them to the DOM.
javascriptCopy code
// JavaScript let newDiv = document.createElement("div"); newDiv.textContent = "Newly created div"; document.body.appendChild(newDiv); // Append to the body element
Removing Elements: You can remove elements from the DOM.
javascriptCopy code
// JavaScript let elementToRemove = document.getElementById("toBeRemoved"); elementToRemove.remove();
Modern JavaScript (ES6+): Utilize modern JavaScript features like arrow functions, destructuring, and spread operators to write cleaner and more concise code.
javascriptCopy code
// Modern JavaScript const myArrowFunction = (param) => console.log(param); const { name, age } = person; // Destructuring const arr1 = [1, 2, 3]; const arr2 = [...arr1, 4, 5]; // Spread operator
These are the foundational concepts for working with the DOM using modern JavaScript. The DOM is a powerful tool that enables you to create dynamic and interactive web applications. As you progress, you'll learn more advanced DOM manipulation techniques and explore additional modern JavaScript features.
Remember to practice regularly and experiment with different scenarios to solidify your understanding. If you have any specific questions or need further clarification on any topic, feel free to ask! Happy coding!
Comments: 24
Kindly check the lecture number 6. Lifecycle of a Change in 1. Git and Github The above lecture is not related to the course please update it ASAP Thank you
From where can I download the files which love babbar says he has uploaded on dashboard ??
I have attached the link https://github.com/lakshayk12/ANN_optimization_BTP
bro, i paid for the course, but still can't access the course. do something
Paid for the course but it still locked, can solve this problem please, when you take the payment the couse should be unlocked, evey time i have to message for any purchase
Now your Paypal payment is accepted and your course is activated successfully. Please leave your valuable feedback.
Why i am being asked for payment if i am already enrolled in the course
Dear anand, your payment is now updated check your course, apologize for several delays. Please leave your valuable feedback.
thanks its working now
hello ,I have a doubt
hello i have a doubt
hi
I'm paying through my Card, but it giving an error. why ? how we can purchase a course in Pakistan. Paypal is banned here
can we download the videos
i done my payment for mern stack development love babbar but cant acces to course kindly give me access
Dear Krishnapal your payment is already accepted go and check back.
Why i am being asked for payment if i am already enrolled in the course
Dear Shivansh, if you already done your payment then contact us on our official Email id [email protected] or reply here.
Why i am being asked for payment if i am already enrolled in the course
Dear p8354046, if you already done your payment then contact us on our official Email id [email protected] or reply here.
Why i am being asked for payment if i am already enrolled in the course
Dear, Don't worry now your problem is solved check your id.
Why i am being asked for payment if i am already enrolled in the course
Yes bro
I'm facing same issue
Dear, Don't worry now your problem is solved check your id.
i want debit card option
how can i assure that this is not scam?
i have same doubt is this website real or a fraud
No its not any fraud. its genuine if you need any proof please contact us via email.
No it's not any scam, its genuine if you need any proof please contact us via email.
how to do payment ?
Click on Watch now button then click next video then payment option is showing
i am unable to access the video even i have already completed my payment .
Your problem is solved
plz add codes lecture wise ! it wold be great and helpful also
now we have added starter package in lecture 2nd, go now and download it.
how to view this one
Why video not play
Now it's working.
Thank you for the access of the videos. It would be greatful if I could no the way to download the videos
Use idm to download
ok
Hello bro can you share course with me?
hello everyone