Ticket #7087 (closed enhancement: cantfix)
allow :enabled and :disabled on <link> tags
| Reported by: | ghartwig | Owned by: | |
|---|---|---|---|
| Priority: | low | Milestone: | |
| Component: | selector | Version: | 1.4.2 |
| Keywords: | Cc: | ||
| Blocking: | Blocked by: |
Description
:enabled really checks !disabled and !hidden. This is fine for <input> tags but not appropriate for <link> tags, which have a disabled property but not a hidden property. The code should check the hidden property only if it exists.
Workaround is to use ":not(:disabled)" instead when trying to select style sheet <link> tags that were not disabled.
Change History
comment:2 Changed 3 years ago by dmethvin
Yeah, I wonder if we're asking for trouble by not defining :enabled as !:disabled (or vice-versa) and having the two be asymmetrical:
enabled: function(elem){
return elem.disabled === false && elem.type !== "hidden";
},
disabled: function(elem){
return elem.disabled === true;
},
Any DOM element without a Boolean disabled property will fail both tests. The API docs vaguely warn about this, and say "input:disabled" should be used, so we could just clarify that warning and say that these two selectors are only intended to be used with inputs:
comment:3 Changed 3 years ago by ghartwig
That's why I don't understand why :disabled isn't working in my case. <link> tags DO appear to have a disabled property (when examined in FireBug), so it seems reasonable that these selectors could be used.
comment:4 follow-up: ↓ 5 Changed 3 years ago by dmethvin
The link element does not have a disabled *property*:
http://www.w3.org/TR/html401/struct/links.html#h-12.3
If you are trying to set a non-standard *attribute* on the link element via .attr() that is not the same thing.
So how are you setting the disabled property on your link elements?
comment:5 in reply to: ↑ 4 Changed 3 years ago by ghartwig
What I'm doing is running through the link tags in the DOM to see which named <link> tags are enabled and saving that value in a cookie in order to remember the user's style sheet selection. I'm not changing the disabled attribute myself right now. The user can change it in Firefox by using the View > Page Style menu items to set which alternate style sheet is active.
I had planned on getting the title via this, but it doesn't work right now because of the :enabled selector: $("link[rel~='stylesheet'][title]:enabled").eq(0).attr("title")
See http://www.alistapart.com/stories/alternate/ This page says:
There is a w3c specified DOM Level 2 attribute, “disabled,” that is set to false when a style sheet is applied to the document.
Please follow the bug reporting guidlines and use jsFiddle when providing test cases and demonstrations instead of pasting the code in the ticket.

Sorry, further research shows the work-around does not work. Apparently, both :enabled and :disabled are always false (I have no explanation for this). My testing was done on Firefox 3.6.10.
New workaround:
// Get the title of the first stylesheet that is not disabled $("link[rel~='stylesheet'][title]").each(function(index) { if (!this.disabled) { title = $(this).attr("title"); return false; } });