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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T16:13:29+00:00 2026-05-24T16:13:29+00:00

I do everything in jQuery but now am going back to learn JavaScript proper.

  • 0

I do everything in jQuery but now am going back to learn JavaScript proper. So how could I do the equivalent of this in vanilla js:

$('ul li a', '#myDiv').hide();
  • 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-05-24T16:13:29+00:00Added an answer on May 24, 2026 at 4:13 pm

    Don’t rely on querySelectorAll(). It doesn’t work in IE <= 7 or FF 3. If you want to use Vanilla JS you need to learn how to write browser compatible code:

    (function(){
        var myDiv = document.getElementById('myDiv');
    
        // Use querySelectorAll if it exists
        // This includes all modern browsers
        if(myDiv.querySelectorAll){
            as = myDiv.querySelectorAll('ul li a');
            for(var i = 0; i < as.length; i++)
                as[i].style.display = 'none';
            return;
        }
    
        // Otherwise do it the slower way in order to support older browsers
    
        // uls contains a live list of ul elements 
        // that are within the element with id 'myDiv'
        var uls = myDiv.getElementsByTagName('ul');
    
        var lis = [];
        for(var i = 0; i < uls.length; i++){
            var l = uls[i].getElementsByTagName('li');
            // l is a live list of lis
            for(var j = 0; j < l.length; j++)
               lis.push(l[j]);
        }
        // lis is an array of all lis which are within uls 
        //within the element with id 'myDiv'
    
        var as = [];
        for(var i = 0; i < lis.length; i++){
            var a = lis[i].getElementsByTagName('a');
            // a is a live list of anchors
            for(var j = 0; j < a.length; j++)
               a[j].style.display = 'none'; // Hide each one
        }
    })();
    

    Here is a JSFiddle. Just so you’re aware, getElementsByClassName() is another commonly used method of traversal which needs an alternative approach if it’s not available (IE <= 8)

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

Sidebar

Related Questions

I implemented this Jquery show/hide code and everything works fine except that the box
I am trying to use BlockUI with jQuery's hide, however, not everything's going to
I have created a dropdown menu with jquery: here Everything is ok but in
I'm using jquery $.getJSON to retrieve list of cities. Everything works fine, but I'm
In jQuery, I've done stuff like this in the past: $('#someCheckbox').click(); And everything works
I am using this and it's working perfectly on the browser http://docs.jquery.com/UI/Sortable Now I
I have this jQuery carousel going: http://dougie.thewestharbour.com/wp-content/themes/dougie/slider.html It works pretty well right now but
I'm a complete jquery newbie, but I'm following this tutorial here to get me
I'm using jquery autocomplete <script src='http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js'></script> <script src='http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.2/jquery-ui.min.js'></script> Everything is working Ok., but now
I have been using the jquery appear plugin for some time now, but it

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.