The DOM (Document Object Model) provides get and set methods to retrieve and update properties or content of HTML elements. Here's an overview:
1. DOM Get Methods
These are used to retrieve or "get" the current values or properties of an element.
Examples:
textContent: Gets the text content of an element.
javascript
Copy code
let text = document.getElementById("example").textContent;
console.log(text); // Logs the text inside the element
value: Retrieves the current value of form elements like input, textarea, or select.
javascript
Copy code
let inputValue = document.getElementById("inputBox").value;
console.log(inputValue); // Logs the input box value
getAttribute(attributeName): Retrieves the value of a specified attribute.
javascript
Copy code
let href = document.querySelector("a").getAttribute("href");
console.log(href); // Logs the href attribute value
innerHTML: Gets the HTML content inside an element.
javascript
Copy code
let htmlContent = document.getElementById("container").innerHTML;
console.log(htmlContent);
2. DOM Set Methods
These allow you to modify or "set" the properties or content of an element.
Examples:
textContent: Updates the text content of an element.
javascript
Copy code
document.getElementById("example").textContent = "New Text Content";
value: Updates the value of form elements.
javascript
Copy code
document.getElementById("inputBox").value = "Updated Value";
setAttribute(attributeName, value): Sets or updates the value of a specific attribute.
javascript
Copy code
document.querySelector("a").setAttribute("href", "https://example.com");
innerHTML: Updates the inner HTML content of an element.
The DOM (Document Object Model) provides mechanisms to interact with HTML elements, allowing developers to dynamically get (retrieve) and set (update) the properties, attributes, or content of elements on a webpage.
What are DOM Get and Set Methods?
Get Methods:
These are used to retrieve values or properties of DOM elements, such as their text, attributes, or styles. For example:
Fetching the text inside a paragraph.
Retrieving the value of a form field.
Getting the attributes (like src or href) of an HTML element.
Set Methods:
These are used to modify or update the values, content, or attributes of DOM elements. For example:
Changing the text content of a heading.
Updating the value of a form field.
Modifying the class or id attribute of an element.
How Do DOM Get and Set Work?
The DOM uses properties and methods to access and modify elements.
These methods operate on DOM nodes, which represent HTML elements in the structure of the webpage..#learnhtml5andcss3#codingchallenge #code #webdevelopment #codewithme #codewithharry#freelance #freecodecamp #sandeepmaheshwari#youtubers #youtube #sandeepmaheshwarimotivational #education #figma #udemyfreecertificate #udemy #frontenddevelopment#codewithharry #education #htmlacademy #htmlcss #css #codehelp #js #upsc #java #codewithharry #frontenddeveloper #javaprogramming#apnacollege #apnacollegestudent #apnacollegestudent #javatutorial#apnacollge #apnacollegestudent #apnacollege #javatutorialsforbeginners#technicalguruji #technicalyogi #technicalanalysis #tutorial #designer #design #engineering #CodingTutorial #CodeWithMe#codehelp #sandeepmaheshwari #sandeepmaheshwarimotivational #ProgrammingTips #DeveloperLife#udemy #figma #TechTips #CodingJourney #CodeChallenge #JavaScript#Python #Java #CSharp#Ruby #PHP #TypeScript #WebDevelopment#WebDevelopment
#LearnWebDev
#CodeWithMe#apnacollege #apnacollegestudent #apnacollge
#FrontendDevelopment
#WebDesign
#JavaScriptTutorial
#HTMLCSS
#CodingForBeginners
#FullStackDev
#WebDevelopmentCourse
#DeveloperTips
#CodingBootcamp #BackendDevelopment#codewithharry #code withharry #FrontendDevelopment #FullStack, #APIs #DatabaseDesign#OOP (Object-Oriented Programming),
#DataStructures #Algorithms#React #NodeJS#Django #Flask#Express, #Angular#VueJS #GraphQL#NextJS #Laravel#SpringBoot #Git#GitHub#Docker #Kubernetes#AWS #Azure#GCP#VSCode #CodingTutorial #CodeWithMe #ProgrammingTips #DeveloperLife #TechTips #CodingJourney #CodeChallenge #viral #viralvideos #youtube #youtubers #codewithharryHashtags: #CSDojo #CodingInterviews #ProgrammingHashtags: #freeCodeCamp #Coding #LearnToCode#codewithharry#codewithherry #shraddhakapra#codingblocks#programminglanguage #codenewbie #coding #earn #freelance #clanguage#codingjourney#WebDevelopment#codewithpython
#FrontendDevelopment
#BackendDevelopment
#FullStackDeveloper
#CodingTutorial
#JavaScript
#LearnToCode