0

Here is my jquery code

(function($){
var W=$(window),
    D=$(document),
    Ht = D.height(),
    Wt = W.width();
$.fn.ThrowMask = function(){
             //Working code
        }
});

i tried to attach this code on button click like this

<script type="text/javascript">
    $(document).ready(function(){
        $("#btn").click(function(){
            ThrowMask();
        });

    });
</script>

But this causes error undefined.

3 Answers 3

2

In addition to Isaac Fife's fix, you need to call the function properly.

<script type="text/javascript">
    $(document).ready(function(){
        $("#btn").click(function(){
            $(this).ThrowMask();
        });
    });
</script>
Sign up to request clarification or add additional context in comments.

3 Comments

Getting an error now...Microsoft JScript runtime error: Unable to get value of the property 'scrollHeight': object is null or undefined
nothing in this code or the code you gave has any reference to scrollHeight, I expect that error to be unrelated to the given code.
Right, but it isn't related to this code. More than likely it is originating within the ThrowMask plugin.
1

You never call the lambda function. use this instead

(function($){
var W=$(window),
    D=$(document),
    Ht = D.height(),
    Wt = W.width();
$.fn.ThrowMask = function(){
             //Working code
        }
})($);

Notice the two extra parens. Added jquery to function call.

4 Comments

You should pass in jQuery as param therefore $ is pointing to jQuery namespace
@Issac Fife Getting an error now...Microsoft JScript runtime error: Unable to get value of the property 'scrollHeight': object is null or undefined
You probably need to put the whole lambda function inside the document.ready, or at least those four variables.
...those four variables into the throwmask function.
0

This is the working code:

(function($){
var W=$(window),
    D=$(document),
    Ht = D.height(),
    Wt = W.width();
$.fn.ThrowMask = function(){
             //Working code which binding click event
             $(this).click(function (event) {
                  // do your click even handler here
             });

        }
}(jQuery));



<script type="text/javascript">
    $(document).ready(function(){
        $("#btn").ThrowMask();

    });
</script>

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.