Bug Tracker

Modify

Ticket #8097 (closed feature: wontfix)

Opened 2 years ago

Last modified 2 years ago

replaceClass

Reported by: rudeboiidevil2k7@… Owned by:
Priority: low Milestone: 1.next
Component: attributes Version: 1.4.4
Keywords: Cc:
Blocking: Blocked by:

Description

jQuery should include a function that replace a class, for example if you wish to replace a class you could do it like this:

$('#element').replaceClass('classname', 'tothisclassname');

Instead of doing something like this:

Would be easier to have this feature, don't you think? :)

$('#element').removeClass('classname');
$('#element').addClass('tothisclassname');

Change History

comment:1 Changed 2 years ago by Alexis Abril

You can actually use toggleClass in this fashion as shown here:  http://jsfiddle.net/mv6mB/

 http://api.jquery.com/toggleClass/

comment:2 Changed 2 years ago by addyosmani

  • Status changed from new to closed
  • Resolution set to wontfix

As mentioned above (and can be seen  here), toggleClass's syntax supports easily switching classes (or replacing as you refer to it) already. Unless there are use-cases which toggleClass would not be appropriate for, we'll be closing this feature/enhancement request as the behavior is already supported.

comment:3 Changed 2 years ago by jitter

  • Priority changed from undecided to low
  • Component changed from unfiled to attributes

comment:4 Changed 2 years ago by danheberden

Also, jQueryUI's toggleClass adds animation support incase you're itching to make that feature request.

Please follow the  bug reporting guidlines and use  jsFiddle when providing test cases and demonstrations instead of pasting the code in the ticket.

View

Add a comment

Modify Ticket

Action
as closed
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.