Bug Tracker

Opened 10 years ago

Closed 10 years ago

#12425 closed bug (invalid)

Doing attr('type', 'hidden') twice when creating a new jQuery element gives an error in IE8

Reported by: alfatek Owned by: alfatek
Priority: undecided Milestone: None
Component: unfiled Version: 1.8.0
Keywords: Cc:
Blocked by: Blocking:


Doing something like this:

var form = $('#form1');
var key = 'lala';
var value = 'life goes on';
$(document.createElement('input')).attr('type', 'hidden').attr('type', 'hidden').attr('id', 'h').appendTo(form);

results in:

Webpage error details

User Agent: Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 5.1; Trident/4.0)
Timestamp: Wed, 29 Aug 2012 19:07:01 UTC

Message: This command is not supported.
Line: 2313
Char: 5
Code: 0
URI: http://ajax.googleapis.com/ajax/libs/jquery/1.8.0/jquery.js

The line that causes the issue is:

elem.setAttribute( name, "" + value );

jQuery already has a "validation check" (type property can't be changed) for this normally but when using createElement the check isn't properly applied.

Test Case: http://jsfiddle.net/LsJmw/5/ There are 3 buttons:

1) normal JS triggers the problem 2) using jquery with attr on an element just created with createElement triggers the problem 3) using jquery on an element that already exists on the page triggers the correct jquery validation check and shows a custom error message

Change History (4)

comment:1 Changed 10 years ago by dmethvin

Owner: set to alfatek
Status: newpending

So it sounds like you understand the problem. Why are you creating an unrealistic test case to induce it? What resolution are you advocating?

comment:2 Changed 10 years ago by alfatek

Status: pendingnew

My point is that, at least, using

$(document.createElement('input')).attr('type', 'hidden').attr('type', 'hidden');


$('#in').attr('type', 'hidden').attr('type', 'hidden');

should have the same result triggering the jQuery validation check "type property can't be changed". The first case doesn't trigger it instead triggering the browser bug.

Someone that happens to use the first example would get an IE8 specific error where one of the goals of jQuery usage is to "abstract" browser specific issues.

comment:3 Changed 10 years ago by dmethvin

Status: newpending

Well the code there can induce the error but isn't realistic. I am assuming you were not aware of the oldIE limitation and managed to find a realistic path where this happened?

I'd actually prefer to remove the check and thrown error completely. I think this is the only place where we so specifically cripple the other browsers in the name of oldIE. When jQuery 2.0 arrives there will not be any reason to have this check.

comment:4 Changed 10 years ago by trac-o-bot

Resolution: invalid
Status: pendingclosed

Because we get so many tickets, we often need to return them to the initial reporter for more information. If that person does not reply within 14 days, the ticket will automatically be closed, and that has happened in this case. If you still are interested in pursuing this issue, feel free to add a comment with the requested information and we will be happy to reopen the ticket if it is still valid. Thanks!

Note: See TracTickets for help on using tickets.