Bug Tracker

Opened 7 years ago

Closed 7 years ago

Last modified 7 years ago

#11931 closed bug (wontfix)

attributeHas selector does not work with jsdom or any other W3C compliant DOM implementation

Reported by: janalex Owned by:
Priority: undecided Milestone: None
Component: unfiled Version: 1.7.2
Keywords: Cc:
Blocked by: Blocking:

Description

The issue boils down into the fact that JQuery assumes that DOM's Element.getAttribute will return null if the attribute in question does not exist but according to W3C specification, if the attribute does not exist, the implementation MUST return an empty string (""). Most of the browsers on the market are returning null (i.e., are not W3C compliant) but any W3C compliant DOM implementation will return "", which in turn makes the attributeHas selector think that the attribute exist when it in fact does not. The recommended way to check for attribute existence is using the Element.hasAttribute function or, as a workaround, use the Element.getAttributeNode which returns null when the attribute does not exist.

More details are in the following forum thread: http://forum.jquery.com/topic/attribute-selector-issue.

Change History (2)

comment:1 Changed 7 years ago by Rick Waldron

Resolution: wontfix
Status: newclosed

Seems silly to break every website using jQuery just because jsdom chose the spec over the defacto standard.

comment:2 Changed 7 years ago by janalex

Just to make sure we understand each other, I'm not suggesting breaking anything. Switching to Element.hasAttribute + Element.getAttribute or Element.getAttributeNode ensures that the implementation will keep working with the non-compliant DOM implementations (i.e., browsers) and, in addition, it will also work with the compliant implementations like jsdom or Mozilla's XUL. I can submit a patch with this change if you want me to - I'm talking about the jQuery.attr function here, specifically the line 2557 in jQuery-1.7.2.js.

It seems silly to me to leave the implementation in the current state that explicitly excludes compliant DOM implementations from working properly with jQuery.

BTW, the site does not let me reactivate this ticket so if somebody knows how to do that I would be grateful if you could reactivate it for me.

--Jan

Note: See TracTickets for help on using tickets.