Skip to main content

Bug Tracker

Side navigation

#8234 closed bug (wontfix)

Opened February 10, 2011 01:30PM UTC

Closed February 10, 2011 05:27PM UTC

Last modified October 11, 2011 03:22PM UTC

Element with id="nodeName" throw exception in Chrome and IE

Reported by: mr.albert.nicolas Owned by:
Priority: low Milestone: 1.next
Component: misc Version: 1.5
Keywords: Cc:
Blocked by: Blocking:
Description

If the DOM contains an element with an id="nodeName", JQuery throw :

  • Chrome 9
Uncaught TypeError: Object #<an HTMLDivElement> has no method 'toLowerCase'
jQuery.extend.acceptDatajquery-1.5.js:1489
jQuery.extend.datajquery-1.5.js:1328
jQuery.extend._datajquery-1.5.js:1483
jQuery.event.handlejquery-1.5.js:2512
jQuery.event.add.elemData.handle.eventHandlejquery-1.5.js:2160
  • IE 8
Webpage error details

User Agent: Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.0; Trident/4.0; SLCC1; .NET CLR 2.0.50727; .NET CLR 3.0.30729; .NET CLR 3.5.30729)
Timestamp: Thu, 10 Feb 2011 13:24:21 UTC


Message: Object doesn't support this property or method
Line: 1489
Char: 4
Code: 0
URI: http://code.jquery.com/jquery-1.5.js

No error with FF3.6

Here a very simple sample : http://jsfiddle.net/JFtYr/3/

Attachments (0)
Change History (4)

Changed February 10, 2011 05:27PM UTC by snover comment:1

resolution: → wontfix
status: newclosed

Do not use reserved DOM names as element IDs.

Changed February 10, 2011 05:54PM UTC by jitter comment:2

component: unfiledmisc
priority: undecidedlow

Hmm looks like I didn't submit my comment and snover closed the ticket in the meantime. Adding anyway:


Thanks for taking the time to contribute to the jQuery project by writing a bug report.

You should have a look at this http://bugs.jquery.com/ticket/7712#comment:5

The problem is that the div is added as expando property to the window object this makes jQuery fail because the window object then "looks like" a DOM element.

It's unlikely that this will get fixed anytime soon (as that would be highly impractical code and size-wise) and it's not a good idea to use reserved names as ID anyway. So you are well advised to read the comment I linked to above and the links in that comment and to change your id/name attributes to "sane" values.

If you can't change the id of this div you might want to try the $(document).ready(...); syntax instead of the $(window).load(...) (unless you specifically need the window load.

You might also want to check #3685, #7472, #7712 and similar tickets to see variations of this problem.

Changed September 14, 2011 10:30PM UTC by info@arstropica.com comment:3

Getting this error with fancybox 1.3.4:

It appears to be trying to pass a function to acceptData. I couldn't identify which part of the code was responsible but I used this as a quick fix:

http://jsfiddle.net/jGes4/

Changed October 11, 2011 03:22PM UTC by info@arstropica.com comment:4

Replying to [comment:3 info@…]:

Getting this error with fancybox 1.3.4: It appears to be trying to pass a function to acceptData. I couldn't identify which part of the code was responsible but I used this as a quick fix: http://jsfiddle.net/jGes4/

A better alternative

http://jsfiddle.net/gyXxK/