Skip to main content

Bug Tracker

Side navigation

#11931 closed bug (wontfix)

Opened June 19, 2012 04:06AM UTC

Closed June 19, 2012 04:26AM UTC

Last modified June 22, 2012 09:07PM UTC

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.

Attachments (0)
Change History (2)

Changed June 19, 2012 04:26AM UTC by rwaldron comment:1

resolution: → wontfix
status: newclosed

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

Changed June 22, 2012 09:07PM UTC by janalex comment:2

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