tags:

views:

46

answers:

1
var form = document.createElement('form');

(form.isDOMForm()) would evaluate to true.

+6  A: 

You mean this:

var form = document.createElement('form');
alert(form.nodeName);

More Info:

http://www.howtocreate.co.uk/tutorials/javascript/dombasics

Note that you can also use tagName but nodeName seems to be a better choice.

Sarfraz
+1 `form.nodeName.toLowerCase() == "form"` will always work.
Pekka
@Pekka, not *always*, it could be either upper or lowercase. Please read: http://ejohn.org/blog/nodename-case-sensitivity/ Other than that gotcha, yes, this is the way to do it.
Aistina
I think that for HTML it is `form.nodeName == "FORM"` in all browsers. EDIT: what @Aistina said.
Sean Hogan
I would also convert it to (e.g.) uppercase before comparing, because I remember observing "FORM" string in firebug - probably case may vary
neutrino
@Aistina good info! Changed my comment.
Pekka
`nodeName` and `tagName` are precisely as good as each other in this situation where we know for certain that we're dealing with an element.
Tim Down