Shauzab Ali Rawjani
Shauzab Ali Rawjani

Reputation: 256

call function when button clicked

i want to call the action() only when the button is clicked. but its not happening :/

$(document).ready(function() {

         var window = $("#space"),
             undo = $("#button");

         undo.bind("click", function() { action(); });

         var onClose = function() { undo.show(); };

         if (!window.data("kendoWindow")) {

              window.kendoWindow({
                  width: "600px",
                  title: "Basic Reports ",
                  close: onClose
              });
         }
});

Upvotes: 0

Views: 105

Answers (4)

Ripa Saha
Ripa Saha

Reputation: 2540

You are using jquery so simply use

$("#Your_button_id").click(function(){
    // place your coding here
});

Upvotes: 0

som
som

Reputation: 4656

undo.bind("click", action);

You can do that this way.

Upvotes: 0

Marius Stănescu
Marius Stănescu

Reputation: 3761

You can use on instead of bind:

$("#button").on("click", function() {
    action();
});

From the jQuery API documentation:

As of jQuery 1.7, the .on() method is the preferred method for attaching event handlers to a document. For earlier versions, the .bind() method is used for attaching an event handler directly to elements. Handlers are attached to the currently selected elements in the jQuery object, so those elements must exist at the point the call to .bind() occurs. For more flexible event binding, see the discussion of event delegation in .on() or .delegate().

Upvotes: 1

pmandell
pmandell

Reputation: 4328

You can simply attach the action function as the event handler like so:

$('#button').click(action);

Upvotes: 3

Related Questions