Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Test: old-style IE createElement #258

Closed
jamesarosen opened this issue May 11, 2011 · 3 comments
Closed

Test: old-style IE createElement #258

jamesarosen opened this issue May 11, 2011 · 3 comments

Comments

@jamesarosen
Copy link

@jamesarosen jamesarosen commented May 11, 2011

In IE < 9, the following is legal:

var e = document.createElement("<input name='foo'></div>");

Indeed, it's the only way to create an element with a name property on older versions of IE.

In Firefox, Chrome, Safari, Opera, and IE 9, it's not. The proper way to do that is:

var e = document.createelement('input');
e.setAttribute('name', 'foo');

I'd love to have a test for old-style IE createElement support:

Modernizr.addTest('htmlCreateElement', function() {
  var result;
  try {
    document.createElement("<input name='test' />");
    result = true;
  } catch(e) {
    result = false;
  }
  return result;
});
@paulirish
Copy link
Member

@paulirish paulirish commented May 13, 2011

how about

document.createElement("<input name='test' />");
result = true;

changes to

return document.createElement("<input name='test' />").getAttribute('name') == 'test';
@jamesarosen
Copy link
Author

@jamesarosen jamesarosen commented May 13, 2011

The problem is that document.createElement("<input name='test' />") will throw an exception on everything except IE6-8. We could do

try {
  return document.createElement("<input name='test' />").getAttribute('name') == 'test';
} catch(e) {
  return false;
}
@paulirish
Copy link
Member

@paulirish paulirish commented May 13, 2011

yup! that's what i meant. :)

@paulirish paulirish closed this in 13d4566 May 21, 2011
patrickkettner pushed a commit to patrickkettner/Modernizr that referenced this issue Feb 22, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
2 participants