• We’re currently investigating an issue related to the forum theme and styling that is impacting page layout and visual formatting. The problem has been identified, and we are actively working on a resolution. There is no impact to user data or functionality, this is strictly a front-end display issue. We’ll post an update once the fix has been deployed. Thanks for your patience while we get this sorted.

javascript woes... should be easy - hiding classes with a twist

Al Neri

Diamond Member
I'm currently making a table of baseball data--

I'm trying to make a table that will hide multiple rows in javascript... now I put together a way to do it by class, but it is not fully doing it the way I wanted it to. I found and built some code as an attempt to get it to work - but apparently I didn't do a good job. Where indexOf is - I changed it from regex - because I want to see if the class contains the text - not if the class IS the text... however it did not seem to work.

The reason for that is, players can be multiple positions.

I'm using PHP to output the positions it's all coming from mySQL. So if the particular player is multiple positions it outputs it as such <tr class="pos-POSITION1-POSITION2-...> for example <tr class="pos-T2B-T1B-LF">...

if he is just one position it is outputted as such <tr class="pos-T1B">

Am I doing something wrong with my code - or what? Thanks so much for the help, see below for the code, I also have it running at

http://www.shopforeveryone.com/test.php

Thanks for any help!

Don R.
 
Ok so you've got a string "pos-T2B-T1B-LF" which I assume signifies that the player plays 2nd base, 1st base and Left Field (talk about a utility player, Ryan Freel eat your heart out). So you want to take and see if the dude plays 1st by saying elem.className.indexOf("T1B") > -1 where elem is the TR tag right?

Seems like that should work to me. What is it doing? Just looked at your page and it looks like you've got it working?
 
In the page you linked, the function getElementsByClass(searchClass,node,tag) is never actually called, and I suspect that's what you want it to be using. You call getElementsByClassName, which calls the built in getElementsByClassName function, and your custom search code never gets called.


Suggestion though: You can in fact have elements that are members of multiple classes. instead of class='position1-position2-position3' have class='position1 position2 position3'. The former puts you in a single class 'position1-position2-position3' - the later is in three seperate classes 'position1', 'position2' and 'position3' Changing any of your multiple position players to a multi-class element instantly makes it function properly.




 
Originally posted by: Al Neri
I'm currently making a table of baseball data--

I'm trying to make a table that will hide multiple rows in javascript... now I put together a way to do it by class, but it is not fully doing it the way I wanted it to. I found and built some code as an attempt to get it to work - but apparently I didn't do a good job. Where indexOf is - I changed it from regex - because I want to see if the class contains the text - not if the class IS the text... however it did not seem to work.

The reason for that is, players can be multiple positions.

I'm using PHP to output the positions it's all coming from mySQL. So if the particular player is multiple positions it outputs it as such <tr class="pos-POSITION1-POSITION2-...> for example <tr class="pos-T2B-T1B-LF">...

if he is just one position it is outputted as such <tr class="pos-T1B">

Am I doing something wrong with my code - or what? Thanks so much for the help, see below for the code, I also have it running at

http://www.shopforeveryone.com/test.php

Thanks for any help!

Don R.

Why are you concatenating class names?
 
Back
Top