Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Add mailto: with jQuery?

<table id="here" border="1">
    <tr><td>London</td><td>[email protected]</td><td>aaa</td><td>aaa</td></tr>
    <tr><td>Manchester</td><td>[email protected]</td><td>aaa</td><td>aaa</td></tr>
    <tr><td>Liverpool</td><td>[email protected]</td><td>aaa</td><td>aaa</td></tr>
    <tr><td>Ipswich</td><td>[email protected]</td><td>aaa</td><td>aaa</td></tr>
</table>

Is possible add link mailto: for second columns with email addresses with jQuery (not modify HTML)? If yes, how?

http://jsfiddle.net/zwsMD/1/

like image 589
Timothy Grees Avatar asked Mar 15 '26 04:03

Timothy Grees


1 Answers

You could just replace the contents of each second td with an a element with a mailto: href: http://jsfiddle.net/zwsMD/5/.

​$("#here td:nth-child(2)").each(function() {
    var email = $(this).text();

    // replace contents
    $(this).html(
        $("<a>").attr("href", "mailto:" + email).text(email)
    );
});​​​​​​​​​​​​​​​​​​​​
like image 106
pimvdb Avatar answered Mar 16 '26 18:03

pimvdb