lets assume the following markup

<a href="#" class="button">a button</a> |
<a href="#" class="button">a button</a> |
<a href="#" class="button">a button</a> |
<a href="#" class="button">a button</a>

you want to be able to differentiate between the buttons on click event

var obj = $(".button");

obj.click(function(e) {
 e.preventDefault();
 var index = obj.index($(this));
 alert("my button index is "+index);
});

this should help

On Fri, Nov 6, 2009 at 11:19 AM, aze <az...@oum.edu.my> wrote:

> Hello,
>
> I need help.
> I have thjis plugin
>
> (function($){
> $.fn.btnInit = function() {
>  function prepare(obj, caption, action) {
>    obj
>        .html(caption)
>        .addClass("fg-button ui-state-default ui-corner-all")
>        .click(function(){
>                  // run the action here when click triggered
>                   alert('Do some action');});
>        };
>
>        return this.each(function(caption, action){
>                obj = $(this);
>                prepare(obj, caption, action);
>        });
>
> };
>
>
> })(jQuery);
>
>
> and the problem is how do I modify the click event so that it can
> accept function as below
>
> $(".btnA").btnInit("Button A", function () { do some action 1 });
> $(".btnB").btnInit("Button B", function () { do some action 2 });
>
> different button will have a different action.
>
> I'm stuck here. Pls help
>
> Thanks
>
>
>

Reply via email to