javascriptjqueryaddclassquit

The jQuery addClass function quits my script


Uhm, I've got this script but it does not work.

It's all about this line: document.getElementById('thetest').addClass('superspecial');

As soon as the class should be added (but it isn't) the whole script quits... Does anybody know why?


Solution

  • Should be:

    jQuery('#thetest').addClass('superspecial');
    

    or

    document.getElementById('thetest').className += ' superspecial';
    

    document.getElementById doesn't return a jQuery element.
    That's why you get has no method error.