I just noticed Glen's reply and looked at that example. It's almost
identical to what i was suggesting with a couple of minor differences that I
thought I'd point out.

His example:

var newURL;
$("td").click(function(){
    newURL = $(this).parents("tr").attr("goto");
    window.location.href = newURL; alert(newURL);
});

the click event is being bound to each td. While there's nothing
particularly wrong with that it's not really necessary. Just bind the click
event to the tr. That's where you wanted it anyway wasn't it? The only time
I really bind click events to td tags is when it's possible that clicking on
one td will do one thing, while clicking on a different td (in the same row)
will do something else.

Also, the code I provided does less work. The selector I chose:
    $("tr[link]")
... tells jQuery to look at only tr tags, and then return only those that
have an expando called "link". While the other example looks at every single
td in the DOM and tries to apply a click to it based on the parent's
expando.

I should also point out that I should probably have var'd my link variable
outside of the function just as a matter of form.

The last difference I want to point out is the use of the .click() method
vs. the .bind() method. Both work just fine. I *think* that the .click()
method is essentially a shortcut for the .bind() method. I'm not sure which
is preferred or "better". It probably comes down to a matter of style.
Someone please feel free to correct me if I'm wrong.

Cheers,
Chris

On 10/20/07, crybaby <[EMAIL PROTECTED]> wrote:
>
>
> I need to have each table rows point to different link.  I am looking
> at table striping and how hover works in 15daysofjquery.com.
>
> http://15daysofjquery.com/table-striping-made-easy/5/
>
> I need to make the whole table row clickable and should take the user
> to a different link on the site.
> How do I do this in jquery?
>
> For example table is as follows:
> <table border="1">
> <tr><td>Row 1 Cell 1</td><td>Row 1 Cell 2</td></tr>
> <tr><td>Row 2 Cell 1</td><td>Row 2 Cell 2</td></tr>
> </table>
>
> Row1 link: site.com/tutorial/1
> Row2 link: site.com/tutorial/2 and so on.
>
>


-- 
http://cjordan.us

Reply via email to