Muzz
Muzz

Reputation: 687

How to share a jquery function

I have the following code that edits text. Normally there is an id used instead of a class. I've changed it to a class because I'd like to share a single instance. Now that it's a class, I can't tell which element the user clicked on.

I want to use one instance of the following code and send in an additional argument that can be passed to my PHP that distinguishes the element and pass that to my PHP code.

$(".edit").edit({
  url:'server.php'
});

So, maybe something like:

function myFunc(arg){
  $(".edit").edit({
    url:'server.php?arg='+arg
  });
}

Of course, this doesn't work because I need the click function and I'm not sure how to do that. Can someone help?

Upvotes: 1

Views: 68

Answers (2)

Sam Tyson
Sam Tyson

Reputation: 4626

This sounds like what you are asking for:

 $(".edit").click( function() { 
     $(this).edit({    
         url: 'server.php?arg=' + $(this).attr('id')
     });
 })

Upvotes: 0

Greg B
Greg B

Reputation: 813

$(".edit").click( function() { 
  $(this).edit({    
    url:'server.php?arg='+arg
  });
})

Is this what you need?

Upvotes: 1

Related Questions