0
var quiz = {

    config : {
        qType : $j('#questionTypeDdown')
    },

    data : {
        qType : 'test'
    },

    init: function() {
        quiz.assignUIActions();
    },

    assignUIActions : function() {

        var c = quiz.config;
        var d = quiz.data;

        quiz.assignqType(c,d);
    },

    assignqType : function(c,d) {
        console.log(c.qType);
        console.log(d.qType);
    }
};

$j(document).ready(function() { quiz.init(); });

console.log(c.qType) returns an empty jQuery object but

console.log(d.qType) returns the value 'test'

Please explain why this is happening and what is the right way to get reference to #questionTypeDdown.

1 Answer 1

2

You're running qType : $j('#questionTypeDdown') before the document is loaded.

You need to execute your object initializer in $j(document).ready.

Sign up to request clarification or add additional context in comments.

4 Comments

see last line $j(document).ready(function() { quiz.init(); });
@Adi: qType : $j('#questionTypeDdown') runs immediately, not when you call your init function.
are you suggesting to move the whole quiz object inside document.ready? How can I make sure the qType : $j('#questionTypeDdown') happens on document ready only?
Yes; that's exactly what I'm suggesting.

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.