views:

34

answers:

2

Hi,

I have a table with many rows. When u click on these rows they open up more detail about the row you click in. This could be based on an int or string.

I have wired jQuery up to anchor tags on each row which the user will click on. However previously when using javascript inline you would pass something like this:

<a href="javascript: openNext('000001')"><img /></a>

Now when using events, i have lost the link to the '000001'. Where should this value be placed for reference?

Cheers

A: 

You could store the data as an ID for the <tr> of the row. Then, in your click handler (assuming it's bound to the <tr>s), call openNext(event.target.id)

Ben
+3  A: 

How about something like this?

<div id="somecontainer">
    <a href="#000001"><img /></a>
    ...
</div>

<script type="text/javascript">
$(function() {
    $('#somecontainer a').click(function() {
        var id = $(this).attr('href').substring(1);
        openNext(id);
        return false;    // to cancel native click event
    });
});
</script>

If you have lots of these on your page, say, over 100, you could also look into jQuery's live feature to increase performance.

Good luck

Funka
sounds good. I also went the route of adding custom attributes to the class. Gives it a bit more meaning.
Schotime