Sam
Sam

Reputation: 57

JQuery - get a variable from the URL to set a CSS value

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

Answers (1)

K K
K K

Reputation: 18099

Instead of $('#pieces[1]').css('color', 'red');

try :

$('#'+pieces[1]).css('color', 'red');

Upvotes: 3

Related Questions