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

  • Home
  • SEARCH
  • 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 9120323
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T05:36:07+00:00 2026-06-17T05:36:07+00:00

Ok. Suddenly I have this query in my mind. Libraries like jQuery makes it

  • 0

Ok. Suddenly I have this query in my mind.

Libraries like jQuery makes it real easy to look for an element having some class. It does not force us to apply an id on the element to be found. In Vanilla js we have the option to find out an element using the method getElementById() which forces me to apply IDs to a large extent.

I looked at this solution to find an element using an attribute which in this case is going to be class. After going through the solutions I find it very heavy on the browser. If I have a complex DOM structure, it will cost performance. And my question remains the same.

How do I find an element using class name and without using id in Vanilla Javascript?

  • 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-17T05:36:08+00:00Added an answer on June 17, 2026 at 5:36 am

    How about

    var elems = document.getElementsByClassName('someclass');
    

    That will return a set of elements which have the given class. You could then access them using elems[0] , elems[1] and so on..

    Remember that jQuery is ultimately based on JavaScript, so it can’t be faster from an execution point of view.

    You might find some interesting jQuery to JavaScript translations here

    http://vanilla-js.com/

    For older versions of IE you need to use getElementsByTagName and loop over the returned elements. This utility function should be compatible from IE6 onwards (probably similar to the solution you linked to)

    function getElementsByAttributeValue(atrName,atrValue) {
        var matchElems = [];
    
        var allElems = document.getElementsByTagName('*');
        for(var x = 0, len = allElems.length; x < len; x++) {
            if(allElems[x].getAttribute(atrName) != atrValue) {
                continue;
            }
    
            matchElems.push(allElems[x]);
        }
    
        return matchElems;
    }
    

    Usage would be:

    var elems = getElementsByAttributeValue("class","someclass");
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have used some jquery components in my web site, Suddenly i'm getting an
I suddenly have an error in my Android eclipse project. This is after a
I have a problem in my company where suddenly 2 users were having problems
I have some Lotus Notes clients that looses server connection. They suddenly get server
I have a query in MS Access (2003) that makes use of a subquery.
I have a stored procedure that goes something like this (pseudo code) storedprocedure param1,
I have suddenly faced a problem with moving some records in a SQL Server
I have this bug where the value of anImage.URL suddenly become nil. anImage is
I suddenly have Run and Search in the menubar of my RCP application. Is
suddenly we have to save kanji (Japanese) in a couple of columns of two

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.