user3052659 user3052659 - 2 years ago 149
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:

Answer Source

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.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download