center is not defined - <!DOCTYPE html> error

I getting error:

ReferenceError: center is not defined

and console marks <!DOCTYPE html>. Why? Without a parameter in the function call everything is fine. All HTML tags are fine, on top I have <!DOCTYPE html>

<button onclick="getRegion(center)" class="btn btn-region">centrum</button>
function getRegion(region) {
    var listRegions = { 
        "center": [ '7', '5' ],
        "south": [ '12' ],
        "north": [ '11' ],
        "west": [ '4' ]
    };
    var activeRegion = listRegions[region];

    //remClass();
    for ( var i = 0; i < activeRegion.length; i++ ) {
        $('section.bok-map').find( $('.pl' + activeRegion[i]) ).addClass('active-region');
    }
}

Answers 1

  • In the getRegion(center) call, center needs to be quoted because you want a string.

    <button onclick="getRegion('center')" class="btn btn-region">centrum</button>
    

    Without the quotes, it is treated as a variable called center which obviously doesn't exist.


Related Articles