Javascript/Jquery to change class onclick?

I want to change a class onclick. What I have at the moment:

function changeclass() {

var NAME = document.getElementById("myclass")



But, ofcourse, its not working. Also, it should revert to previuos state onclick again.

My html:

<div id="showhide" class="meta-info" onclick="changeclass();">

So, whenever I press on #showhide myclass should change to mynewclass. Thanks for help in advance!


With jquery you could do to sth. like this, which will simply switch classes.

$('.showhide').click(function() {

If you want to switch classes back and forth on each click, you can use toggleClass, like so:

$('.showhide').click(function() {