Link to home
Start Free TrialLog in
Avatar of RadhaKrishnaKiJaya
RadhaKrishnaKiJaya

asked on

Make Java script click event dynamic

Hi Experts,
I have this Java script. How can I make the click dynamic so that this function can be called on the click event of any button.

Thanks.

<script type="text/javascript">
        $(document).ready(function () {
            $('#btnSubmit').click(function () {
                $('.blockMe').block({
                    message: 'Please wait...<br /><img src="Image/Wait.gif" />',
                    css: { padding: '10px' }
                });
            });
        });
</script>
Avatar of Jeffrey Dake
Jeffrey Dake
Flag of United States of America image

Jquery uses selectors just like css. You currently are using the #btnSubmit, which is looking for an element with an id of btnSubmit. If you change that to A it would then select all links on the page, so if an anchor tag was clicked the function would be executed.

$('A').click(function () {

Hope that is what you are looking for
Use jQuery button selector $( ":button" ) or $( "button, input[type='button']" ) like below
<script type="text/javascript">
        $(document).ready(function () {
            $(':button').click(function () {
                $('.blockMe').block({
                    message: 'Please wait...<br /><img src="Image/Wait.gif" />',
                    css: { padding: '10px' }
                });
            });
        });
</script> 

Open in new window

Avatar of RadhaKrishnaKiJaya
RadhaKrishnaKiJaya

ASKER

Hi Prakash,

Thank you for your reply. How can I pass the ID of the button to this function. For example if submit button is click then it should btnSubmit and if btnSave is clicked then btnSave.

Thanks.
ASKER CERTIFIED SOLUTION
Avatar of Prakash Samariya
Prakash Samariya
Flag of India image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Thank you.