javascript - Unable to replace the class of div element - no method named css -


i want replace old class of html element new 1 using jquery. here i'm doing:

var elem = $('.my_selector')[0]; elem.css('class', 'my_new_class'); 

but error saying "uncaught type error: object#<htmldivelement> has no method css.

how fix it?

the problem trying call jquery method css() (even not relevant here) dom element, derived [0]. can use toggleclass() job:

$(".my_selector:first").toggleclass("my_selector my_new_class"); 

Comments

Popular posts from this blog

Why does Ruby on Rails generate add a blank line to the end of a file? -

keyboard - Smiles and long press feature in Android -

node.js - Bad Request - node js ajax post -