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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T14:59:27+00:00 2026-06-14T14:59:27+00:00

I am trying to make a javascript function that goes through the web page

  • 0

I am trying to make a javascript function that goes through the web page and looks for all of the tags of class name "option" and hides the ones that match the text in each of the if statements shown below.

In the example below, I tried using jquery to get the classes, but it only gets the first class with that name, not all of the classes of that name.

I have also tried using var element = document.getElementsByClassName('option'); to see if that would work but when I iterated through the list of elements and changed their display to none, the changes didn’t show up.

What is a better way to iterate through a list of classes and update the css of only some of the elements?

Any help is appreciated. Thanks.

$(document).ready(function(){

if($('.option').html() == "C. "){
    $('.option').css('display','none');
}
if($('.option').html() == "D. "){
    $('.option').css('display','none');
}
if($('.option').html() == "E. "){
    $('.option').css('display','none');
}
if($('.option').html() == "F. "){
    $('.option').css('display','none');
}
});
  • 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-14T14:59:29+00:00Added an answer on June 14, 2026 at 2:59 pm

    You’re not getting only one element, you just simply only manipulating the “first” element in the jQuery Object that is returned by the $('.option') call. What you need to is jQuery’s .each() function in order to iterate through ALL of the elements returned by the jQuery call. Also, the long if statement can be shortened, but I assume you knew that and have other purposes. Anyway, once .each is called, you can use the callback function to manipulate EACH element as it is passed through. This is much like a for loop. The parameter i in the following example represents the index value of the element as the object is iterated through. It is 0 based, in other words, the 3rd option element to pass through would set the param i to 2

    Try this && Good Luck:

    $(function() {
        $(".option").each(function(i) {
            var txt = $(this).text();
            if (txt == "C." || txt == "D." || txt == "E." || txt == "F.")
                $(this).hide();
        });
    })
    

    Alternate links to investigate

    • .html()
      • Use this method to get or set the innerHtml of an element
    • .val()
      • Use this method to get or set the value of an element
        • Primarily HTML tags select, input, && textarea
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've been trying to make a JavaScript function for a Google Chrome web-application that
I'm trying to make a Javascript function that will take a mathematical expression and
I am trying to make a Javascript that loops infinitly. function scroll(num) { $(.
I'm trying to make a <table> through a javascript function. I'm getting a JSON
I am trying to make a javascript function (although jquery is perfectly OK) that
I'm trying to make a javascript function with a regex, that will validate a
I have a JavaScript function that goes through a list of checked checkboxes and
I'm trying to make a JavaScript bookmarklet that will act as a highlighter, changing
So i am trying to make a function that searches trough an xml file,
I am trying to make a JavaScript (jQuery is fine as well) function to

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.