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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T16:54:01+00:00 2026-06-16T16:54:01+00:00

I have been wondering why people glorified jQuery’s $(".myClass") method when JavaScript has a

  • 0

I have been wondering why people glorified jQuery’s $(".myClass") method when JavaScript has a generic document.querySelector(). Is there something I’m missing here? Why not just use the document object?

I am completely new to JavaScript, so is there some type of con to document.querySelector() that I am not aware of?

I’d really like to know, because I ran across something like this earlier and I’m wondering if it might help a situation I’m in:

var retrieve = function( s ) {
    return document.querySelector( s );
};

retrieve(".myClass").style.display = "block";

Note

I have nothing against jQuery at all. In fact, I love it. However, I’d rather not cheat myself using the easy pre-made ready-to-use tools when I’m just now trying to learn JavaScript.

Any help would be much appreciated! 🙂

  • 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-16T16:54:02+00:00Added an answer on June 16, 2026 at 4:54 pm

    Cross-browser and legacy support.

    You can also use getElementsByClassName() if you don’t want to use Jquery. There is a response to a post on devshed by user: KorRedDevil that may be of interest to you.

    I took your function from your post and made it return an array. After you have that array of elements, all you have to do is loop over them. You can try it out here.

    Javascript:

    var retrieve = function(className) {
        return document.getElementsByClassName(className);
    };
    
    var elements = retrieve('foo');
    for (var i = 0; i < elements.length; i++)
        elements[i].style.background = '#dfd';
    

    Markup:

    <p class="foo">foo</p>
    <p class="bar">bar</p>
    <p class="foo">foo</p>
    <p class="foo">foo</p>
    <p class="bar">bar</p>
    <p class="bar">bar</p>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have been wondering about how people manage their strings if they are likely
I ran into this RegExp /[[0]]/ in JavaScript, and have been wondering what it
This has been asked before and people have given very good instructions on how
I have always been wondering how other people get to align to the centre
I have been wondering for a while, after asking different people and without any
I have been creating a Javascript/jQuery heavy application for Windows Phones and iPhones. The
I have been wondering about the following lines of code [self performSelector:@selector(myMethod) withObject:self afterDelay:1.0];
I have been wondering and couldn't find a clear answer on this subject. Imagine
I have been wondering about the reload() function in python, which seems like it
I have been wondering about the performance of regular expression implementations lately, and have

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.