Edward Potter Edward Potter - 7 months ago 17
Javascript Question

Trying to beautify a line of jQuery

I'm doing variable substitution in a jquery expression. It just looks kind of ugly. Wondering if someone knew a better way to do this?

... looping through a calendar, looking at dates to high-light in a calendar table, code excerpt:

var = 31;
$('#s' + var + '').css({"background-color":"blue","color":"white"});


This does work, just the syntax is a bit un-elegant. Thanks.

Answer

You shouldn't need the $('#s' + var + ''). This should be enough:

var xyz = 31;
$('#s' + xyz).css({"background-color":"blue","color":"white"});

I am sure this is just an example, but don't name a var var.

Comments