Bug Tracker

Ticket #7087 (closed enhancement: cantfix)

Opened 4 years ago

Last modified 3 years ago

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:1 Changed 4 years ago by ghartwig

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;
   }
});

comment:2 Changed 4 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:

 http://api.jquery.com/disabled-selector/

comment:3 Changed 4 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 4 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 4 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.

comment:6 Changed 4 years ago by snover

  • Status changed from new to open
  • Summary changed from :enabled rejects all <link> tags regardless of whether they are disabled or not to allow :enabled and :disabled on <link> tags
  • Type changed from bug to enhancement
  • Milestone 1.4.3 deleted

comment:7 Changed 3 years ago by john

  • Status changed from open to closed
  • Resolution set to cantfix

If you're hitting problems everywhere then this is also failing in the browser's querySelectorAll engine - and I don't think that that's something that we're going to try and override and "fix".

Note: See TracTickets for help on using tickets.