You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: Courses/IBM-JavaScript-Essentials/README.md
+60Lines changed: 60 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1797,3 +1797,63 @@ Finding elements within a container involves searching for and accessing HTML el
1797
1797
</body>
1798
1798
</html>
1799
1799
```
1800
+
1801
+
- Styling DOM Elements:
1802
+
1803
+
1. style property - You can directly access and modify the inline styles of an HTML element using the style property. This method is beneficial for dynamically adjusting the appearance of elements based on user interactions or events.
2. classList property - The class list property facilitates adding, removing, or toggling CSS classes on an element. This property is especially useful for applying predefined styles from CSS classes and enables the toggling of classes in response to user interactions.
1825
+
1826
+
```
1827
+
element.classList.add(className)
1828
+
element.classList.remove(className)
1829
+
element.classList.toggle(className)
1830
+
element.classList.contains(className)
1831
+
```
1832
+
1833
+
3. setAttribute - The setAttribute method allows you to set or modify the style attribute of an element using a string containing inline CSS.While effective, the set attribute process replaces the entire style attribute of an element.
1834
+
1835
+
```html
1836
+
<html>
1837
+
<body>
1838
+
<pid="myText"style="color: red">This is a red text</p>
4. remove property - the remove property method is useful for selectively removing specific CSS properties from an element's inline style, this method provides a way to reset or adjust styling on a granular level.
1848
+
1849
+
```html
1850
+
<html>
1851
+
<body>
1852
+
<pid="myText"style="color: red; font-size: 30px;">This is a red text</p>
0 commit comments