JS Bootcamp Session3
JS Bootcamp Session3
JS Bootcamp Session3
DOM Manipulation
Contents
Js boot session3
SK S&T
7. Handling Events:
• Introduce event handling with JavaScript.
• Cover common events like click, mouseover, and submit.
• Discuss event propagation.
8. Best Practices:
• Discuss best practices for efficient and maintainable DOM
manipulation code.
• Emphasize the importance of performance considerations.
9. Q&A and Recap:
• Allow participants to ask questions.
• Summarize key concepts covered during the workshop.
Js boot session3
SK S&T
• getElementById:
• Example: document.getElementById('myElement')
Js boot session3
SK S&T
• getElementsByClassName:
• Example: document.getElementsByClassName('myClass')
• getElementsByTagName:
• Example: document.getElementsByTagName('p')
• querySelector:
Js boot session3
SK S&T
3. Example Usage:
// Represents the number of elements with class 'myClass' when the list was created
// Represents the number of elements with class 'myClass' when the list was created
Explanation:
textContent sets or gets the text content within an element, treating content as plain
text.
Js boot session3
SK S&T
Attention :
Js boot session3
SK S&T
Explanation:
Explanation:
• The style property allows you to directly manipulate the inline CSS of an
element.
• classList provides methods like add and remove to manipulate the classes of
an element.
• By changing classes, you can apply predefined styles or toggle between
different styles.
Js boot session3
SK S&T
Explanation:
Js boot session3
SK S&T
7. Handling Events:
Understanding Events:
Events are occurrences or interactions that happen in the browser, such as a user
clicking a button, submitting a form, or moving the mouse. JavaScript allows us to
listen for these events and execute specific code in response.
Types of Events:
Click Event:
Mouseover Event:
Submit Event:
Js boot session3
SK S&T
While the examples provided cover common events, there are many more
event types you might encounter. Some examples include:
Key Events:
• Triggered when a user presses or releases a key.
Change Event:
• Fired when the value of an input element changes.
Resize Event:
• Occurs when the size of the browser window changes.
Example :
Explanation:
• addEventListener is used to attach an event handler to an element. It takes the
event type and a callback function as parameters.
• Common events include click, mouseover, submit, etc.
• The event object (event) passed to the callback contains information about the
event and methods like preventDefault() to prevent the default behavior.
Js boot session3