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 8238549
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T19:51:18+00:00 2026-06-07T19:51:18+00:00

I know you use the attr method to get the attribute for the first

  • 0

I know you use the attr method to get the attribute for the first item in a matched set, e.g. $('input').attr('name') gives you the name attribute for the first matched input element.

But how do I get the attribute directly from an HTML element, e.g. $('input')[0]? I’d like to do something like $('input')[0].attr('name') but that doesn’t work, as attr is only a method of jQuery matched sets, not the items within matched sets.

(By the way, this has come up because I’d like to pass items from within a matched set to a function, and be able to see the attributes of that item within the function.)

  • 1 1 Answer
  • 0 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. Editorial Team
    Editorial Team
    2026-06-07T19:51:20+00:00Added an answer on June 7, 2026 at 7:51 pm

    If by [0] you simply want to get a specific element from a matched set, used eq():

    $(selector).eq(0).attr('name');
    

    Will get the name attribute of the first element in the set returned by the selector. Of course, the the 0 can be replaced by the index number of any element returned by that selector.

    Similarly, you could use the :eq() selector:

    $('div:eq(0)').attr('name');
    

    Or, if selector is a variable:

    $(selector + ':eq(0)').attr('name');
    

    As Alnitak notes, in the comments below:

    If you’re going to use eq, use .eq(n) rather than :eq(n) so that the browser can use querySelectorAll() – the latter is a jQuery extension.

    Of course, you could, for certain names, or properties, just fall back to the DOM methods:

    $(selector)[0].name;
    

    Or:

    $(selector)[0].getAttribute('name');
    

    References:

    • :eq().
    • eq().
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Now i know to use the method of float.Parse but have bumped into a
I know you use the C based networking API to do FTP communication but
I know and use eric meyer CSS reset, but is there any more things
I know you can use source control software for source code, but can you
I have got this form: <form action='/Admin/Update' method='post'> <input type='text' name='dataUpdate' value= + $temp
I want to set a read-only attribute inside a class method. I have already
Somebody know how use OpenX (php app) with Django? I need to use OpenX
I know the use of WCF in SA is deprecated because it will move
I know and use the standard c# regex library, and I love it. It
so far i only know to use Ctrl-Shift-A to do SVN in TextMate. is

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.