Opened 14 years ago
Closed 13 years ago
#4630 closed enhancement (wontfix)
Add radioClass method
Reported by: | brandon | Owned by: | brandon |
---|---|---|---|
Priority: | low | Milestone: | 1.next |
Component: | attributes | Version: | 1.3.2 |
Keywords: | needsreview | Cc: | |
Blocked by: | Blocking: |
Description
radioClass method (inspired by Ext Core) adds a class to one element and removes it from its siblings. Attached is a patch to include radioClass into jQuery. This creates a dependency of the selectors module to the attributes module which didn't exist before. I didn't use the .siblings() method so as not to create another dependency on traversing.
Attachments (1)
Change History (15)
Changed 14 years ago by
Attachment: | radioClass.diff added |
---|
comment:1 Changed 14 years ago by
Definitely good addition. I need this too often not to appreciate such a method.
+1
comment:4 Changed 14 years ago by
Would these two then be equivalent?
$(foo).radioClass('on'); $(foo).addClass('on').siblings().removeClass('on');
Even though Ext may go with radioClass, it doesn't specifically target radio's which can appear misleading; siblingClass() would be more logical to me.
But on the whole, it doesn't seem to be enough of an improvement to deserve it's own syntactic sugar. This would also be the only attribute manipulation method that assumes a specific DOM relationship. A bit odd to me.
-1
comment:5 Changed 14 years ago by
not so sure this needs to be in core (though it seem some people like it). the name is certainly misleading, and i think that if something like this is going to go in, it way as well work natively to apply this behaviour on checkboxes, which at present wouldn't really be manipulated by this enhancement.
comment:6 Changed 14 years ago by
I'm in agreement with paul.irish in both the naming and usefulness. The method would only be useful when dealing with exclusive classes in sibling relationships.
If you wanted to add something like this, I'd would say it is more valuable to have some flexibility.
Assuming you had
<div id="parent"> <h3>heading</h3> <ul> <li class="active">1</li> <li>2</li> </ul> <h3>heading</h3> <ul> <li>1</li> <li>2</li> </ul> <h3>heading</h3> <ul> <li>1</li> <li>2</li> </ul> </div>
Something like...
$("#parent ul:last li:first").exclusiveClass('active', $("#parent"));
Where the second argument would be the scope that you should maintain exclusiveness within (perhaps making it so that the default scope is within the direct parent).
-1
comment:8 Changed 14 years ago by
I agree with my chums from #jquery.
I'd rather see these type of extension functions go into an 'optional' lib which would be available to download alongside the core. Lets keep the core lean and mean.
comment:10 Changed 13 years ago by
Component: | unfiled → attributes |
---|
comment:11 Changed 13 years ago by
Milestone: | → 1.5 |
---|---|
Priority: | major → low |
Status: | new → open |
Needs review/attention
comment:12 Changed 13 years ago by
Keywords: | needsreview added |
---|---|
Milestone: | 1.5 → 1.next |
comment:13 Changed 13 years ago by
To have the same behavior as the Ext method, radioClass must also take an array of classes, as in my little plugin here:
http://code.doublerebel.com/jQuery/jquery.radioclass.js
Interestingly, this ticket was filed (and various radioclass blog posts were written) about the same time I created that. I think radioClass would definitely see use.
comment:14 Changed 13 years ago by
Resolution: | → wontfix |
---|---|
Status: | open → closed |
Without a public repo, unit tests or docs, it's hard to support something that already seems easily accomplished with existing core methods - as noted by paul.irish
-1
radioClass method