0

I'm making an ajax call that is pulling back a table of items, each row begins with an edit button. I want to assign an "onclick event" or equivalent to each of these edit buttons so that they pass the specific item id to a function...which will in turn make another ajax call to pull specific info about that item. I've read several postings that use .live but have failed to see any that allows a specific id to be passed in so that dynamic data can be pulled. Any thoughts?

2
  • My thoughts: you did not explain what actually you cannot perform. Give us some examples in code. Commented Jul 24, 2011 at 2:34
  • show your html structure. please only provide the relevant part of the code Commented Jul 24, 2011 at 2:34

1 Answer 1

2

Try something like this. I am assuming the edit button in a td within tr and there is an itemId attribute for each tr to be used to make a ajax call on button click.

The below code is using live so that when you add update the table or add more rows to this table the edit button click will be fired for all the buttons without even attaching the new events.

$("editButtonSelector").live("click", function(){
   var itemId = $(this).closest("tr").attr("itemId");
   //Now use this itemId to pass to the ajax call you make.
});
Sign up to request clarification or add additional context in comments.

1 Comment

Very nice solution, thank you. I've been looking at the problem from only one direction. Thanks again.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.