addClass() passing function as parameter doesn't behave as expected
- <script src="https://code.jquery.com/jquery-1.10.2.js"></script>
-
- <p></p>
- <p></p>
-
- <script>
- $target=$('p').first();
- $target.text('plz');
- $target.addClass('red');
- $target.addClass(
- function(i,c)
- {
- var added;
- if (c==='red')
- {
- this.removeClass('red');
- added='blue';
- }
- return added;
- }
- );
- </script>
-
- <style>
- .blue
- {
- color: blue;
- }
-
- .red
- {
- color: red;
- }
- </style>
The text doesn't turn blue.