tags:

views:

83

answers:

1

How would you do something like this:

somemethod($("#buttonelement"));

function(ele) {
  ele.click(function(event) { alert("hi"); });
}

in other words how do you pass in an element as a jquery object and register the click event.

+10  A: 

Just like that...?

function someMethod(ele) {
    ele.click(function(event) {
        alert("hi");
    });
}

someMethod($("#buttonelement"));

The jQuery object is just like any other object in Javascript and can be passed to functions as normal.

nickf