English 中文(简体)
j Query - 出入证
原标题:jQuery - Pass element to function

Hi I have a function that i want to pass an element to via clicking the element or calling the function with the element as a paramter. This is what I have:

function change_btm_cat(item) {
        $( div.prod_matrix ).removeClass( block );
        $( div.prod_matrix ).addClass( none );
        $( div.prod_matrix# +item.attr( id )).removeClass( none );
        $( div.prod_matrix# +item.attr( id )).addClass( block );
        $( div.btm_cat ).removeClass( green_grad );
        $( div.btm_cat ).addClass( grey_grad );
        item.removeClass( grey_grad );
        item.addClass( green_grad );
        //ps. i know its messy, just testing stuff
    }

我可以轻而易举地利用:

$( div.btm_cat ).click(function() {
        change_btm_cat($(this));
    });

但当我尝试:

$( another.element ).live( click , function() {
   change_btm_cat($( div.btm_cat#7 ));
});

这似乎对这项职能没有任何影响。

See jsFiddle for working example:

最佳回答
问题回答

审判:

$( div.btm_cat ).click(change_btm_cat);

function change_btm_cat()
{
     $(this) //becomes available
}

以及

$( another.element ).live( click , change_btm_cat);




相关问题
getGridParam is not a function

The HTML: <a href="javascript:void(0)" id="m1">Get Selected id s</a> The Function: jQuery("#m1").click( function() { var s; s = jQuery("#list4").getGridParam( selarrrow )...

selected text in iframe

How to get a selected text inside a iframe. I my page i m having a iframe which is editable true. So how can i get the selected text in that iframe.

jQuery cycle page with links

I am using the cycle plugin with pager functionality like this : $j( #homebox ) .cycle({ fx: fade , speed: fast , timeout: 9000, pager: #home-thumbs , ...

jquery ui dialog opens only once

I have a button that opens a dialog when clicked. The dialog displays a div that was hidden After I close the dialog by clicking the X icon, the dialog can t be opened again.

jConfirm with this existing code

I need help to use jConfirm with this existing code (php & Jquery & jAlert). function logout() { if (confirm("Do you really want to logout?")) window.location.href = "logout.php"; } ...

Wrap text after particular symbol with jQuery

What I m trying to do, is wrap text into div inside ll tag. It wouldn t be a problem, but I need to wrap text that appears particularly after "-" (minus) including "minus" itself. This is my html: &...

热门标签