Reputation: 23801
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.
Upvotes: 0
Views: 2461
Reputation: 5757
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>
Upvotes: 0
Reputation: 1689
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.
Upvotes: 1
Reputation: 95017
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>
Upvotes: 2