Bug Tracker

Opened 14 years ago

Closed 12 years ago

Last modified 11 years ago

#4417 closed bug (duplicate)

problem with attribute name when clone in IE7

Reported by: boneazul Owned by:
Priority: low Milestone: 1.5
Component: manipulation Version: 1.3.2
Keywords: clone attribute Cc:
Blocked by: Blocking:


there is a problem in IE7 when clone elements, after change name elements .

I want to clone a tr element ,but clone in FF and IE7 show diferents results look the example

Attachments (5)

jquery_close.html (412 bytes) - added by boneazul 14 years ago.
clone_function_upgraded.js (2.6 KB) - added by boneazul 14 years ago.
new clone method
jquery.js (118.8 KB) - added by boneazul 14 years ago.
jquery1.3.2 with method clone modified
teste.HTML (948 bytes) - added by boneazul 14 years ago.
test case .html
test_v2.HTML (4.1 KB) - added by jerone 14 years ago.
test v2

Download all attachments as: .zip

Change History (21)

Changed 14 years ago by boneazul

Attachment: jquery_close.html added

comment:1 Changed 14 years ago by boneazul

alert test in FF3 shows me <td><input id="test" name="a[]"></td>

when in IE7 shows me <td><input id=test name=a></td>

is this a bug??

comment:2 Changed 14 years ago by jerone

IE7 is correct here; as W3C says

ID and NAME tokens must begin with a letter ([A-Za-z]) and may be followed by any number of letters, digits (![0-9]), hyphens ("-"), underscores ("_"), colons (":"), and periods (".").

comment:3 Changed 14 years ago by boneazul

the problem is not in the name with especial caracters.

Change the concat "[]" to another letter like "b" in this script the same problem is detected follow this code



<title></title> <meta content=""> <style></style>

<script src="http://code.jquery.com/jquery-latest.js"></script> <script>


this point we concat the name white letter b (W3C says that is not wrong) ok? $("#test").attr('name',$("#test").attr('name')+"b"); Now we clone the line var obj_tr_clone=$("#line").clone(true); Show html clone alert(obj_tr_clone.html());



</head> <body>


<tr id="line">

<td><input id="test" name="a"></td>


</table> </body>


In fact what happened .

1 - We change the name "a" to "ab" 2- Clone the line 3 - Alert the html clone

FF is ok because he shows me the new name in alert -> "ab" "<td><input id="test" name="ab"></td>"

but in IE7 he shows me the old name in alert -> "a" and don't change the name (its wrong as i can see) why he don't change the name??? "<td><input id=test name=a></td>"

who is wrong ?? the method clone()?? the method html()?? or IE7??

sorry about my poor english..

comment:4 Changed 14 years ago by boneazul

IE copies events bound via attachEvent when

using cloneNode. Calling detachEvent on the clone will also remove the events from the orignal In order to get around this, we use innerHTML.

Unfortunately, this means some modifications to attributes in IE that are actually only stored as properties will not be copied (such as the the name attribute on an input).

i found it in script jquery.js the problem looks like in IE7 Unfortunately i'm right??

comment:5 Changed 14 years ago by dmethvin

Yes, this looks like it has also been reported in a slightly different situation in ticket #4422. It seems like IE is stripping off the quotes and that is causing some bizarre problems.

comment:6 Changed 14 years ago by boneazul

i found the problem....

in fact jquery use outerHTML to clone the html element and IE7 respond with the first html rended(why??i don't now)

example if you render first

<input type="text" name="a" id="aa"> and change any attribute via javascript after dom loaded like (name,id) or any framework javascript will not be correct avaiable in outerHTML method

html always will be cloned as <input type="text" name="a" id="aa"> same as any attribute be modified

however a way to fix it, is upgrade method clone in jquery to find all childs inside outerHTML and replace this attibutes like (name,id,size,...) to real values .there is possible and it is easy to do.I will write a pseudo code then workaround this ..and suggest to core jquery to fix this problem.

and pray to IE fix it.. :)

comment:7 Changed 14 years ago by jerone

Maybe it's an idea to temporary store these attributes before cloning and attach them after.

comment:8 Changed 14 years ago by boneazul

ok i'm here again... i wrote a little code upgrading method clone in jquery core to fix the problem with name in IE6 + that not suport jQuery.support.noCloneEvent

and i would like ask you to test the code..

works fine in the diferents test cases..

if you want to update or upgrade the code to some more simple or generic thats ok...

just give me the credits.. :)

@Jonatan de Sá Lemes - Brazil

i guess then i solvet it in 14 lines to aggregate in core function ...

the codes and tests cases is attached

Changed 14 years ago by boneazul

Attachment: clone_function_upgraded.js added

new clone method

Changed 14 years ago by boneazul

Attachment: jquery.js added

jquery1.3.2 with method clone modified

Changed 14 years ago by boneazul

Attachment: teste.HTML added

test case .html

comment:9 Changed 14 years ago by jerone

I did some testing of your script and it seems it works great.

The only problem with it was that it worked with browser identification, which is a big no in jQuery. I've come up with a support solution that checks if the browser has support for special characters in attributes (name).

I've updated your test file with the new function.

Hope it gets approved.

Changed 14 years ago by jerone

Attachment: test_v2.HTML added

test v2

comment:10 Changed 14 years ago by boneazul

now it's great.Thank you for you helping. i did some another tests and the problem doens't happen with another attributes like id,size,etc just with name attribute..very strange..: ) .it's ok now.

this change will be applied in jquery clone method v1.3.3 ???

i hope so.if not thank you.help'm a lot.

comment:11 Changed 13 years ago by vishvananda

this is still causing issues with trailing slashes in action parameters of forms. Is there a decent workaround? For now I'm adding the action after I clone the form

comment:12 Changed 13 years ago by dmethvin

Component: unfiledmanipulation

comment:13 Changed 12 years ago by grjasewe

It is a problem for struts2-jquery-grid. See http://www.trirand.com/blog/?page_id=393/help/multiple-search-multiple-criteria-same-field/#p19979. Any more news on a resoultion for this bug?

comment:14 Changed 12 years ago by SlexAxton

Keywords: clone attribute added
Milestone: 1.41.5
Priority: majorlow
Status: newopen

comment:15 Changed 12 years ago by snover

Resolution: duplicate
Status: openclosed

This ticket is confusing. Closing as a duplicate of the much clearer #6236.

comment:16 Changed 12 years ago by snover

Duplicate of #6236.

Note: See TracTickets for help on using tickets.