Side navigation
#7312 closed bug (wontfix)
Opened October 26, 2010 07:57AM UTC
Closed November 10, 2010 08:26PM UTC
Last modified March 14, 2012 12:46AM UTC
add class does not work for multiple calls
Reported by: | igor.lazarevski@gmail.com | Owned by: | igor.lazarevski@gmail.com |
---|---|---|---|
Priority: | low | Milestone: | 1.5 |
Component: | attributes | Version: | 1.4.3 |
Keywords: | Cc: | ||
Blocked by: | Blocking: |
Description
Hi jQuery team.
First of all, i very much like the job that you are doing and please do keep on doing this.
I have one question about addClass method when multiple called on the same element. If I use pure JS like this
<style type="text/css">
#test{width:400px;}
.blue{background-color:Blue;}
.red{background-color:Red;}
</style>
...
document.getElementById('test').className = 'blue';
document.getElementById('test').className = 'red';
document.getElementById('test').className = 'blue';
document.getElementById('test').className = 'red';
document.getElementById('test').className = 'blue';
document.getElementById('test').className = 'blue';
document.getElementById('test').className = 'blue';
it works just fine. But when i use jQuery for the same call...
$('#test').addClass('blue');
$('#test').addClass('red');
$('#test').addClass('blue');
it does not affect the element with the new class. Can you please explain to me why is acting like this? Is this as it proper way of working or is it something else?
Thank you in advance.
Attachments (0)
Change History (5)
Changed October 26, 2010 01:13PM UTC by comment:1
component: | unfiled → attributes |
---|---|
owner: | → igor.lazarevski@gmail.com |
status: | new → pending |
Changed October 26, 2010 10:19PM UTC by comment:2
Changed November 08, 2010 09:28PM UTC by comment:3
priority: | undecided → high |
---|---|
status: | pending → open |
Changed November 10, 2010 05:02PM UTC by comment:4
Using .className
sets the class attribute to the specified value. addClass only adds the class if it's not present. You should use a removeClass('red') before adding blue
to the element.
Changed November 10, 2010 08:26PM UTC by comment:5
priority: | high → low |
---|---|
resolution: | → wontfix |
status: | open → closed |
Can you distill this into a reduced test case on jsFiddle - thanks!