How to get class name through JavaScript

Here i am explaining how to get class name through JavaScript using id and u can also change class name.
How do get the class name through JavaScript given no id with this span.

Like: This is a simple span, here i am getting class name using id of span.

    var className=document.getElementById("xyz").className;
    if(className=="xyz")
    {
       alert(className);
    }
    else
    {
        document.write("This is not a valid class name");
        alert(className);
    }
About Author

My name is Mukesh Jakhar and I am a Web Application Developer and Software Developer, currently living in Jaipur, India. I have a Master of Computer Application in Computer Science from JNU Jaipur University. I loves to write on technology and programming topics. Apart from this, I love to travel and enjoy the beauty of nature.

Sign up for weekly update

Milkshake is almost ready. If you're interested in testing it out, then sign up below to get exclusive access.