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

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

how about

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

changes to

return document.createElement("<input name='test' />").getAttribute('name') == 'test';

@jamesarosen
Copy link
Author

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

yup! that's what i meant. :)

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
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants