Hey there! I'm working on customizing the style of some elements (specifically td
s within a table) based on the current URL. Here are the pages I'm targeting:
http:\\domain\site\welcome.html
http:\\domain\site\press.html
http:\\domain\site\contact.html
All these pages share a common table
structure and I need to tweak the styling of the td
s accordingly.
Here's the HTML setup:
<table>
<tr>
<td id="welcome" class="default">Welcome</td>
<td id="press" class="default">Press</td>
<td id="contact" class="default">Contact</td>
</tr>
</table>
And here's the CSS for it:
.default {
//custom settings
}
.current {
//custom settings
}
Basically, if the URL contains the word welcome
, I want the td
with an id
of welcome
to have a class
of current
. I've tried using jQuery but it doesn't seem to be working as expected:
<script src="jquery-1.4.2.min.js">
$( document ).ready(
function() {
if (document.URL.indexOf("welcome") > -1)
{
document.getElementById("welcome").className = "current";
}
else if (document.URL.indexOf("press") > -1)
{
document.getElementById("press").className = "current";
}
else if (document.URL.indexOf("contact") > -1)
{
document.getElementById("contact").className = "current";
}
});
</script>