Sunday, December 12, 2010

finding determining determine the type of an element (tag type) using jquery

Try following ways:

// 'this' won't point to the element when it's inside the ajax closures,
// so we reference it using a variable.
var element = this;

// get the id
alert("element.id: " + element.id);

// different ways of getting the tag type.
alert("element.nodeName: " + element.nodeName);
alert("element.tagName: " + element.tagName);
alert("element.tagName: " + $("#" + element.id).get(0).tagName);

//The following will return true if the element is an input:
alert("element.tagName: " + $("#" + element.id).is("input"));

No comments: