Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I change an elements class in jquery?

Tags:

jquery

css

Assuming I have <ul class="myList verticalList"> how can I change the value of verticalList using jquery?

like image 708
Mohamad Avatar asked Dec 30 '25 09:12

Mohamad


2 Answers

Try a combination of addClass and removeClass

$(selector).removeClass('verticleList').addClass('newClass');

Also, did you mean: vertical

like image 190
Ken Browning Avatar answered Jan 01 '26 23:01

Ken Browning


I thnik what you want to do is remove that class and change to another? see addClass and removeClass

$('.verticalList').addClass('foo').removeClass('verticalList') 

P.S. I've corrected spelling of 'vertical' in this version

like image 31
tobyodavies Avatar answered Jan 01 '26 23:01

tobyodavies



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!