user3052659 user3052659 - 5 months ago 20x
Javascript Question

Inline jQuery unexpected token switch

Stumped as to why this simple code keeps giving me a

Uncaught SyntaxError: Unexpected token switch

$(document).ready(function() {
setInterval('switch()', 5000);

function switch(){
var $active = $('#placeholder');
var $next = $;


I thought functions can be outside the
function? When I tried putting
inside the
function, it gave me the same error. My jsfiddle:


As the error message indicates, switch is a keyword, and thus may not be used as a function name. To fix the issue, rename your function to something else, such as mySwitch.