Mahendra
Mahendra

Reputation: 3837

jquery like code not working inside switch

My code is

//global variable
var topMenuSelected = 'Hot';

function switchMenu() {
     switch(topMenuSelected){
            case 'Hot':
                ${'#hotMenu'}.css('color', '#fff');
                break;
            case 'All':
                ${'#allMenu'}.css('color', '#fff');
                break;
        default:
                break;
        }
}   

Here hotMenu and allMenu are ids of a tag <a>. On click of these links I am calling this function to change the color of <a>. But the error like invalid character is coming for $ character in switch

Upvotes: 0

Views: 108

Answers (2)

Loktar
Loktar

Reputation: 35309

A few things

First change ${'#hotMenu'} to $('#hotMenu')

Also make sure you are loading jQuery first, and its also a good idea to wrap your intiliazing code within

$(function(){
    //Code here
});

Upvotes: 4

John K.
John K.

Reputation: 5474

This needs to use "(" rather than "{"

${'#hotMenu'}.css('color', '#fff');

$('#hotMenu').css('color', '#fff');

Upvotes: 1

Related Questions