Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 98585
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T00:13:26+00:00 2026-05-11T00:13:26+00:00

I am looking to extend jQuery so I can easily retrieve the tagName of

  • 0

I am looking to extend jQuery so I can easily retrieve the tagName of the first element in a jQuery object. This is what I have come up with, but it doesn’t seem to work:

$.fn.tagName = function() {     return this.each(function() {         return this.tagName;     }); } alert($('#testElement').tagName()); 

Any ideas what’s wrong?

BTW, I’m looking to use this more for testing than in production.

  • 1 1 Answer
  • 2 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. 2026-05-11T00:13:27+00:00Added an answer on May 11, 2026 at 12:13 am

    Try this instead:

    $.fn.tagName = function() {     return this.get(0).tagName; } alert($('#testElement').tagName()); 

    To explain a little bit more of why your original example didn’t work, the each() method will always return the original jQuery object (unless the jQuery object itself was modified). To see what is happening in each with your code, here is some pseudocode that shows how the each() method works:

    function each(action) {     for(var e in jQueryElements) {         action();     }     return jQueryObject; } 

    This is not how each() really gets implemented (by a long shot probably), but it is to show that the return value of your action() function is ignored.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have fancy looking jQuery Multiple checkbox/selectbox list script. Look HERE for demo. This
I'm looking to extend the regex below so I can have unlimited number of
Looking to do a bit of refactoring... Using NHibernate I have this query currently
How can use the slideDown() function with easing? Maybe extend it somehow? I'm looking
I essentially have the same goal as in this question: Calling a jQuery plugin
Sorry If something like this has already been asked, but I can't find exactly
I have been reading here and there about multiple JQuery selectors but I couldn't
Im looking to extend the jquery tabs to add next and previous buttons -
Im looking for a jQuery alternative to this plugin: upPrev: NYTimes Style Next Post
This is my first attempt at a jquery plugin and I've looked at a

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.