How to change class of HTML element in JavaScript

1146765 pts.
Tags:
HTML
JavaScript
Would there be a way I can change the class of a HTML element just in case of a resposne to an onlick? I would have to use JavaScript too.
0

Answer Wiki

Thanks. We'll let you know when a new response is added.
Send me notifications when members answer or reply to this question.

Discuss This Question: 1  Reply

 
There was an error processing your information. Please try again later.
Thanks. We'll let you know when a new response is added.
Send me notifications when members answer or reply to this question.
  • clark445kent
    Hi,

    You will try this to change class
    • document.getElementById('id').classList.add('class');
    • document.getElementById('id').classList.remove('class');
    And to toggle a class (remove if exists else add it):
    • document.getElementById('id').classList.toggle('class');
    I hope it will be work for you.

    Thanks & Regards
    Clark Kent
    8,235 pointsBadges:
    report

Forgot Password

No problem! Submit your e-mail address below. We'll send you an e-mail containing your password.

Your password has been sent to:

To follow this tag...

There was an error processing your information. Please try again later.

Thanks! We'll email you when relevant content is added and updated.

Following

Share this item with your network: