Camirlot Camirlot - 26 days ago 5x
Javascript Question

Use jQuery ID Selector with CSS

I'm actually creating a list with streamers and checking if they're online, if so they'll get a green background color.

Now I want to create an additional list next to my "team list" which includes every streamer.

For this I'm trying to use the same method like the one I'm using for the background color.


(to color every background color for the streamers)

But now I want to just hide the streamers in one list and not everywhere.

So I can't use this:

$(".".concat(user)).css("display", "none");

(would hide every offline streamer in every list)

I already tried to apply the ID but actually I don't know how.
If I use this:

$("#online".concat(user)).css("display", "none");

nothing happens.

(I named my ID online)

<tr class="header" id ="online">

(I already tried to apply the id to a new , to the and now to the but nothing works)


I want to hide offline streamers in a new list but I can't use the same ID selector as I used before. How can I do it?


Not much to start with, but if you have a structure like

        <tr class="header Peter" id ="onlinePeter">
        <tr class="header John" id ="onlineJohn">
        <tr class="header Michael" id ="onlineMichael">
        <tr class="header Bob" id ="onlineBob">
        <tr class="header Daniel" id ="onlineDaniel">

and a script like

var user = "John";
$("#online".concat(user)).css("display", "none");
user = "Daniel"

It works. the row that contains John disappears

On the other piece of code where you try to change the background color, you are calling an element with the class = user, but the HTML you provided only has the class "header", once the class is added, the background changes as well.