How to toggle class using pure javascript in html

0 votes

I have a <div>, and I want to toggle its classes on hover.

Here is my code:

function a(){
    this.classList.toggle('first');
    this.classList.toggle('sec');
}
document.querySelector('#container').addEventListener('click', a );

I am confident there is no issue with my HTML or CSS. Simply put, I need to make a change and substitute something else for the click, but I'm not sure what.

Please assist!

Jul 26, 2022 in HTML by Tejashwini
• 3,820 points

edited 5 days ago 6 views

No answer to this question. Be the first to respond.

Your answer

Your name to display (optional):
Privacy: Your email address will only be used for sending these notifications.
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP