Webolution Designs

Modifying DOM Elements

Share This Post

Once we can grab DOM elements, we can modify them. There are several methods to change DOM elements. If we would like to set the attribute on an element…

let myElem = document.getElementById(‘elementId’); myElem.setAttribute(‘attributeName’,‘attributeValue’
); 

If we would like to add a class to an element…

let myElem = document.getElementById(‘elementId’); myElem.classList.add(‘className’); 

If we would like to change the style of an element…

let myElem = document.getElementById(‘elementId’); myElem.style.color = ‘#333’; 

Here we can use color names, RGB(a), hex codes and HSL(a).

We can even change the text content of an element…

let myElem = document.getElementById(‘elementId’); myElem.textContent = ‘Here is some new text!’; 

Happy Coding!

Clay Hess

Subscribe To Our Newsletter

Get updates and learn from the best

More To Explore

Code

Curriculum Innovation or Confusion

It is an early Monday morning just prior to the beginning of the semester.  A faculty member walks into the institution where he teaches.  He

Code

Creating a Promise

Promises are used for asynchronous code. It is a temporary holder for a value that gets returned by an asynchronous call. For example, a call

Do You Want To Boost Your Business?

drop us a line and keep in touch

Excuse Our Mess! We are currently remodeling!

We are currently in the process of redesigning our site. We appreciate your patience as some areas of our site show chipping and paint peeling. We hope to have it sparkling soon!

small_c_popup.png

Learn how we helped 100 top brands gain success.

Let's have a chat