Jquery: how to trigger td a when tr is clicked

Posted by Poku on Stack Overflow See other posts from Stack Overflow or by Poku
Published on 2010-05-14T07:33:22Z Indexed on 2010/05/14 7:44 UTC
Read the original article Hit count: 241

Filed under:
|

Hey,

I have a table where the first td in the trs contains a link. I want this anchor to be triggered (clicked) no matter where i click in the containing tr.

I have read and tried alot of recents post and suggentions on this topic but i can't get this to work. I tried the trigger() and triggerHandle() functions, but it does not trigger the anchor click that i want.

There must be others who have had the need to trigger a anchor click when a tr is clicked, so that the user doesn't have to click the tds anchor link. It sure is a nice UI feature if its possible?

Here is the code i have tried:

<head> 
    <meta http-equiv="content-type" content="text/html; charset=utf-8" />  
    <script type="text/javascript" src="javascripts/jquery-1.4.2.js"></script>
    <script type="text/javascript" charset="utf-8">
        /* Initialise the table with the required column sorting data types */
        jQuery(document).ready(function () {
            jQuery("#rowClick tr").click(function (e) {
                jQuery("#clickevent", this).trigger("click");
            });
        });
    </script> 
</head> 
<body id="dt_example"> 
    <table id="rowClick">
        <thead>
            <tr>
                <th style="width: 30px">id</th>
                <th style="width: 200px">navn</th>
            </tr>
        </thead>
        <tbody>
            <tr>
                <td><a href="datatabletext.asp?test=1" id="clickevent">1</a></td>
                <td>Jesper</td>
            </tr>
            <tr>
                <td><a href="datatabletext.asp?test=2" id="clickevent">2</a></td>
                <td>Bjarne</td>
            </tr>
            <tr>
                <td><a href="datatabletext.asp?test=3" id="clickevent">3</a></td>
                <td>Søren</td>
            </tr>                            
        </tbody>
    </table>
</body> 

© Stack Overflow or respective owner

Related posts about JavaScript

Related posts about jQuery