Ticket #7312 (closed bug: wontfix)
add class does not work for multiple calls
| Reported by: | igor.lazarevski@… | Owned by: | igor.lazarevski@… |
|---|---|---|---|
| Priority: | low | Milestone: | 1.5 |
| Component: | attributes | Version: | 1.4.3 |
| Keywords: | Cc: | ||
| Blocking: | Blocked by: |
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.
Change History
comment:1 Changed 3 years ago by rwaldron
- Owner set to igor.lazarevski@…
- Status changed from new to pending
- Component changed from unfiled to attributes
comment:3 Changed 3 years ago by rwaldron
- Priority changed from undecided to high
- Status changed from pending to open
Please follow the bug reporting guidlines and use jsFiddle when providing test cases and demonstrations instead of pasting the code in the ticket.

Can you distill this into a reduced test case on jsFiddle - thanks!