Skip to content

alingrig87/DOM-Manipulation

Repository files navigation

DOM Manipulation

Accessing Elements

The basic concept in DOM manipulation is accessing HTML elements using methods like getElementById, getElementsByClassName, or getElementsByTagName.

01 Accessing Elements

Modifying Content

You can modify the content of an HTML element using properties like innerHTML or textContent. For example, you can change the text within an element or add new elements inside an existing one.

Modifying Attributes

You can change or add attributes for an HTML element using methods like setAttribute or removeAttribute. For example, you can change the source of an image or add a class to an element.

Manipulating CSS Styles

You can manipulate the CSS styles of HTML elements using the style property. For instance, you can change the background color or dimensions of an element.

Adding and Removing Classes

You can add or remove classes for an HTML element using methods like classList.add, classList.remove, or classList.toggle. This allows you to apply or remove specific CSS styles for that element.

Handling Events

You can attach or remove events for an HTML element using methods like addEventListener or removeEventListener. This allows you to respond to user actions, such as a click on an element or hovering over it.

Traversing and Modifying the DOM Tree

You can traverse and modify the DOM tree using methods like parentNode, childNodes, nextSibling, and previousSibling. These methods allow you to navigate between elements and make changes accordingly.

Creating New Elements

You can create new HTML elements using the createElement method and add them to the DOM using methods like appendChild or insertBefore. This enables you to generate and add dynamic content to the page.

Removing Elements

You can remove an element from the DOM using the remove method or by removing it from its parent using the removeChild method. This allows you to eliminate unnecessary elements or temporarily hide them.

Manipulating Input Values

You can access and modify the input values of HTML elements, such as text fields, selects, or checkboxes. This way, you can retrieve or update the data entered by the user.

About

No description, website, or topics provided.

Resources

Stars

1 star

Watchers

1 watching

Forks

Releases

No releases published

Packages

 
 
 

Contributors