> > From: Laurent Yaish
> >
> > I couldn't find a way using jQuery to get the tagName of an element.
> >
> > Let's say I have this:
> >
> > <div><span>test</span></div>
> > $('span').parent().tag() would return 'div' 

> From: Brandon Aaron
> 
> You could do two things ... write yourself a plugin that 
> would look something like this:
> 
> jQuery.fn.tag = function() {
>   return this[0] ? this[0].tagName : null; };

That would certainly do the trick. I can't resist a little code
optimization... :-)

jQuery.fn.tag = function() { return this[0] && this[0].tagName; };

> or you could just do it like this:
> 
> $('span').parent().get(0).tagName

Or:

  $('span').parent()[0].tagName

Although here I can see where one might prefer the .get(0) for clarity - not
sure which I like better.

-Mike


_______________________________________________
jQuery mailing list
[email protected]
http://jquery.com/discuss/

Reply via email to