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
Post a Comment