Reputation: 57
I wrote this code in order to set the text color of an active menu item:
$(document).ready(function () {
var url = window.location.href;
var pieces = url.split("?whatPage=");
$('#pieces[1]').css('color', 'red');
});
If I alert pieces[1]
I get the value of the ID of the relevant menu item, but the menu item's color is unaffected. What is most likely to be going wrong?
Upvotes: 0
Views: 321
Reputation: 18099
Instead of $('#pieces[1]').css('color', 'red');
try :
$('#'+pieces[1]).css('color', 'red');
Upvotes: 3