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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T08:36:24+00:00 2026-05-26T08:36:24+00:00

I am creating an array of div tags inside the player table div. I’m

  • 0

I am creating an array of div tags inside the player table div. I’m getting all div tags with class .players. The divs with class name .players have input fieds and a link field inside. I want to be able to manipulate these (remove, add class, etc…)

What I thought would work would be something like:

$(divarray[j]+' .link').hide();
$(divarray[j]+' a').remove('.link');

But it’s not working. Any thoughts? I’m sure it’s something simple but it’s my first time at JS 🙂

var divarray = $('#player-table > .players');
        for( var j = 0; j < 10; j++){
        $(divarray[j]).removeClass("players");
        $(divarray[j]).addClass("selected_players");
        $('#debug').append(divarray[j]);
        $(divarray[j]+' a').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-26T08:36:24+00:00Added an answer on May 26, 2026 at 8:36 am

    First of all, you cannot just concatenate jQuery objects or DOM nodes with strings to create new selectors. jQuery provides methods for this kind of situations, where you already have an object or DOM node and want to find other related nodes.

    Second, with jQuery there are much better ways to process a set of elements. Here is your code in more jQuery-like way. This is just an example, because I don’t know the HTML structure. You have to adjust it so that it selects and applies to the correct elements.

    $('#player-table > .players').slice(0,10) // gets the first 10 elements
     .removeClass("players")                  // removes the class from all of them
     .addClass("selected_players")            // adds the class
     .find('a').hide().end()                  // finds all descendant links and hides them
     .appendTo('#debug');                     // appends all elements to `#debug`
    

    As you maybe see, there is only one semicolon at the last line. That means this whole code block is just one statement, but splitting it up over several lines increases readability.

    It works because of the fluent interface, a concept which jQuery heavily makes use of. It lets you avoid creating jQuery objects over and over again, like you do ($(divarray[j])).

    Another advantage is that you can work on the whole set of elements at once and don’t have to iterate over every element explicitly like you have to do with “normal” DOM manipulation methods.

    For learning JavaScript, I recommend the MDN JavaScript Guide.
    jQuery has a couple of tutorials and a very good API documentation.

    Read them thoroughly to understand the basics. You cannot expect to be able to use a tool without reading its instructions first.

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

Sidebar

Related Questions

I have 2 divs that I am creating from an array: $.each(data, function(i,item) {
I'm creating my own JavaScript Array-like object and I have methods that call closures.
I am creating a form with multiple checkboxes with the same name. I have
I'm creating a bunch of Divs based on the number items in an array
I have this Class/Object: function Shape(){ this.xArray = new Array(); this.yArray = new Array();
I am creating an array of string objects in PowerShell which needs to be
Why is it that for user defined types when creating an array of objects
When creating a 3D array in C#, which is a better way to create
I'm creating a numpy array which is to be filled with objects of a
If you are creating a 1d array in Python, is there any benefit 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.