[Bug 17708] New: DOMTokenList: Ability to swap a class

https://www.w3.org/Bugs/Public/show_bug.cgi?id=17708

           Summary: DOMTokenList: Ability to swap a class
           Product: WebAppsWG
           Version: unspecified
          Platform: PC
        OS/Version: All
            Status: NEW
          Severity: normal
          Priority: P2
         Component: DOM
        AssignedTo: annevk@annevk.nl
        ReportedBy: w3c@marcosc.com
         QAContact: public-webapps-bugzilla@w3.org
                CC: mike@w3.org, www-dom@w3.org


This is a feature request to add the ability to swap one class for another in
DOMTokenList. 

At the W3C advance mobile web dev course, we recently ran an "experiment" where
we asked students to use CSS's "transition:" to show and hide a <p> element
based by clicking on a <h1> element (see https://vimeo.com/43676508 for a video
of what they were asked to build). 

In the results the students submitted, we saw a lot of this:

$("article").removeClass("closed").addClass("opened");

If developers are going to swap CSS classes around in the method above, then
they might as well have an efficient means to do that. 

Or other similar code. We also saw evidence that developers assume that class
lists retain order:

if(elem.classList === "x y") {
   .... 
} 

This could lead to confusion when using DOMTokenList toggle(), as toggle
destroys the ordering of CSS class list names of an attribute.  

Given the above, I'll like to request we add swap() method to DOMTokenList().
It would swap one token for another while retaining item order.

-- 
Configure bugmail: https://www.w3.org/Bugs/Public/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are the QA contact for the bug.

Received on Friday, 6 July 2012 21:29:12 UTC