Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to call custom jquery function onClick

Hi. I am new to jQuery.. I want to know how to call custom jQuery function by onClick attribute of HTML. This was the basic I was trying.Further I want to make parametrised function and want to call that function onClick attribute.

my jQuery function is:

jQuery.fn.myFadeIn=function() {
    return $('#fadeInDiv').fadeIn();
};

and the HTML is:

<input type="radio" name="contentCalls" class="radioButton" id="Calls" onclick="myFadeIn();">

<div id="fadeInDiv">
div to open
</div>

Thanks!

like image 483
Shruti Avatar asked Sep 14 '09 12:09

Shruti


1 Answers

This plugin alert()s the ID of each matched element:

jQuery.fn.alertElementId = function()
{
    return this.each(function()
    {
        alert(this.id);
    });
};

And to use it:

// alert() each a-element's ID
$("a").click(function ()
{
    $(this).alertElementId();
});
like image 132
cllpse Avatar answered Sep 26 '22 00:09

cllpse