-
May 21st, 2023, 09:37 AM
#1
[RESOLVED] JS Hide column in table
I have a page that has multiple tables on it. I need to be able to dynamically hide/show one of two columns on one table and need to show or hide 3 of 6 columns in another table and I need to do this without hiding columns in the other tables that are present.
The code below hides the column and the header just fine in the first table.
Code:
$(' td:nth-child(3),th:nth-child(3)').hide();
The problem is that it also hides columns in other tables which I do not want hidden.
I tried adding a class to the table and use that in the call as in the line below
Code:
$('.general td:nth-child(3),th:nth-child(3)').hide();
Same result where it does what I need in one table but hides stuff in other tables as well.
I've been searching for a while now looking at lots of different examples of how to hide a column but have yet to find a way to restrict it to a specific table.
Any tips?
-
May 21st, 2023, 03:50 PM
#2
Re: JS Hide column in table
I have also tried
Code:
$('#ITCase td:nth-child(3),th:nth-child(3)').hide();
Where ITCase is the id of the table in question.
This also correctly hides the column in the ITCase table but also hides columns in other tables.
I need for it to hide either column 2 or 3 in table ITCase and columns 1,2 and 3 or columns 4,5 and 6 in table ITComponents and not hide any columns in the other tables that are on the page. The groups of columns to be hidden are determined based on the result of a query.
-
May 21st, 2023, 04:00 PM
#3
Re: [RESOLVED] JS Hide column in table
Looks like I have it, I added the id to the th part as well and it looks to be only affecting the table desired.
Code:
$('#ITCase td:nth-child(3),#ITCase th:nth-child(3)').hide();
-
May 22nd, 2023, 07:12 AM
#4
Re: [RESOLVED] JS Hide column in table
I always filter "down" the DOM - this is two distinct branches coming off the TABLE. I would have done it with TWO $().hide() calls.
Apparently by specifying the #ID, you pull it back UP the DOM, to then find the TH children.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|