1

apparently my jquery function is not defined. I have no idea why. I am calling jquery before the scripts file so thats not the case and the jquery was working fine before I put it in the function.

(function ($) {

function selectCharacter(){
    $('select.character_select').change(function(){

        alert('Select field value has changed to' + $('select.character_select').val());



    });
}

})(jQuery);


selectCharacter();
1

1 Answer 1

5

This is a scope issue. function creates a new scope. So, you're trying to invoke a private variable to your function outside of your function. You can fix this by changing where you invoke the function:

(function ($) {
    function selectCharacter() {
        $('select.character_select').change(function() {
            alert('Select field value has changed to' + $('select.character_select').val());
        });
    }       
    selectCharacter();
})(jQuery);
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.