0% found this document useful (0 votes)
9 views

DOM Manipulation Methods in JavaScript

Uploaded by

ysirola9410
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
9 views

DOM Manipulation Methods in JavaScript

Uploaded by

ysirola9410
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 8

DOM Manipulation Methods

@_codevalley
Zuhaib Asif
@_codevalley Zuhaib Asif

Content Manipulation Method

innerHTML:
It is used to gets or sets the HTML content
within an element.

let element = document.getElementById("myElement");


element.innerHTML = "New content";
@_codevalley Zuhaib Asif

Content Manipulation Method

innerText:
It is used to gets or sets the text content
within an element.

let paragraph = document.getElementById("myParagraph");


paragraph.innerText = "New text";
@_codevalley Zuhaib Asif

Content Manipulation Method

textContent:
It is similar to innerText, gets or sets the text
content within an element.

let paragraph = document.getElementById("myParagraph");


paragraph.textContent = "New text";
@_codevalley Zuhaib Asif

Attribute Manipulation Method

setAttribute(name, value):
It is used to sets the value of an attribute on
an element.

let image = document.getElementById("myImage");


image.setAttribute("src", "new.jpg");
@_codevalley Zuhaib Asif

Attribute Manipulation Method

removeAttribute(name):
It is used to removes a specified attribute
from an element.

let image = document.getElementById("myImage");


image.removeAttribute("src");
@_codevalley Zuhaib Asif

Style Manipulation Method

style:
It is used to access or modifies the inline
styles of an element.

let element = document.getElementById("myElement");


element.style.color = "blue";
@_codevalley Zuhaib Asif

Style Manipulation Method

classList:
It is used to manipulates the classes of an
element.

let element = document.getElementById("myElement");


element.classList.add("newClass");
element.classList.remove("oldClass");

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy