Hey weird question but I am writing some code and I want to clean it up… The code goes as follows…
function (item){
if(item == "1")
$('div').show();
if(item == "2"
$('div1').show();
}
I tried something like
function (item)
var $div = div+item;
$($div).show()
Thanks
Assuming you mean
#div+ n, sincediv1is not a valid selector. However, the logic should be the same no matter what the prefix of your actual selector is.Example: http://jsfiddle.net/XXSTy/
For information on the conditional operator, check this MDN article.