2

First off the URL is being posted from a different page:

http://www.xxredxiiixx.com/games/

click a link to take to example

http://www.xxredxiiixx.com/games/PS4/Knack#42

This is showing the LAST trophy (#42) for Knack

I have this code already (jQuery)

var hash = location.hash.replace("#","");    
$(hash).removeClass("row").removeClass("row1").addClass("row2");

The var gets the #42 correctly but I cant seem to alter the class to highlight the selected trophy. The IDs are just simply numbered accordingly

<tr class="row<?php echo ($j++ % 2 == 0 ? '' : '1'); ?>" id="<?php echo $xmb; ?>">
<tr class="row" id="42">

Any help would be great.

.row2 td{
    background-color: #FFF;
}
.row1 td{
    background-color: #242424;
    border-top: 1px solid #121212;
}
.row td{
    background-color: #2a2a2a;
    border-top: 1px solid #121212;
}

var hash = location.hash.replace("#","");
$(hash).removeClass("row").removeClass("row1").addClass("row2");

<tr class="row" id="42">

3 Answers3

2

You do not have to give dot . in addClass and removeClass functions.

$(hash).removeClass("row row1").addClass("row2");
Adil
  • 143,427
  • 25
  • 201
  • 198
1

You remove the # leaving you with the string 42. Then you try to use 42 as a selector which is wrong. Do not remove the # symbol.

var hash = location.hash; // "#42"
$(hash).removeClass("row row1").addClass("row2");

You might want to look at this question:
What are valid values for the id attribute in HTML

Community
  • 1
  • 1
Salman A
  • 248,760
  • 80
  • 417
  • 510
0

removeClass is a function only to remove classes from elements. no need to specify it as a . class selector

$(hash).removeClass("row").removeClass("row1").addClass("row2");
zzlalani
  • 21,360
  • 16
  • 42
  • 72