Created
July 25, 2010 16:48
-
-
Save aarongustafson/489679 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| function createElementWithName( type, name ){ | |
| var element; | |
| // First try the IE way; if this fails then use the standard way | |
| if( document.all ){ | |
| element = | |
| document.createElement( '< '+type+' name="'+name+'" />' ); | |
| }else{ | |
| element = document.createElement( type ); | |
| element.setAttribute( 'name', name ); | |
| } | |
| return element; | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| function createElementWithName(){} | |
| (function(){ | |
| try { | |
| var el=document.createElement( '<div name="foo">' ); | |
| if( 'DIV'!=el.tagName || | |
| 'foo'!=el.name ){ | |
| throw 'create element error'; | |
| } | |
| createElementWithName = function( tag, name ){ | |
| return document.createElement( '<' + tag + ' name="' + | |
| name + '"></' + tag + '>' ); | |
| } | |
| }catch( e ){ | |
| createElementWithName = function( tag, name ){ | |
| var el = document.createElement( tag ); | |
| // setAttribute might be better here ? | |
| el.name = name; | |
| return el; | |
| } | |
| } | |
| })(); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| var createElementWithName = ( function(){ | |
| try { | |
| var el = document.createElement( '<div name="foo">' ); | |
| if( el.tagName !== 'DIV' || el.name !== 'foo' ){ | |
| throw 'create failed'; | |
| } | |
| return function( tag, name ){ | |
| return document.createElement( '<' + tag + ' name="' + | |
| name + '"></' + tag + '>' ); | |
| }; | |
| }catch( e ){ | |
| return function( tag, name ){ | |
| var el = document.createElement( tag ); | |
| el.setAttribute( 'name', name ); | |
| return el; | |
| }; | |
| } | |
| })(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment