When the page has loaded, I want to add a class to an element with an ID of contact_page:
<a id="contact_page">Contact</a>
This is the JavaScript code I’m using:
$(document).ready(function () {
$("contact_page").addClass('selected');
});
It should be adding the class, but when I run it, nothing happens.
What am I doing wrong, and how can I fix it?
You need to use # to select an id in jquery
See example here http://jsfiddle.net/S4aAx/7/ also you do not need to add document ready or script in jsfidle it does it for you.