stackoverflow: how to get the text of second TD with all tr having class warning

http://stackoverflow.com/questions/18416408/how-to-get-the-text-of-second-td-with-all-tr-having-class-warning

HTML

<table class="table">
    <tr class="warning">
        <td> 1 </td>
        <td> name </td>
        <td> address </td>
        <td> phone no </td>
        <td> Location </td>
    </tr>
    <tr>
        <td> 3 </td>
        <td> name2 </td>
        <td> address2 </td>
        <td> phone no2 </td>
        <td> Location2 </td>
    </tr>
    <tr class="warning">
        <td> 6 </td>
        <td> name5 </td>
        <td> address5 </td>
        <td> phone no5 </td>
        <td> Location5 </td>
    </tr>
    <tr>
        <td> 7 </td>
        <td> name6 </td>
        <td> address6 </td>
        <td> phone no6 </td>
        <td> Location6 </td>
    </tr>    
    <tr>
        <td> 8 </td>
        <td> name6 </td>
        <td> address6 </td>
        <td> phone no6 </td>
        <td> Location6 </td>
    </tr>
</table>

<br />

<div id="warning-names">
    Warning Names:
    <ul id="name-list">
    </ul>
</div>

JavaScript

$(function() {
    //use the :nth-child selector to get second element
    //iterate with .each()
    $('table tr.warning td:nth-child(2)').each(function(index, element) {
        var name = $(element).html();
        $('#name-list').append('<li>' + name + '</li>');
    });
    $('table tr td:nth-child(2)').on('click',function()
    {
    		$('#name-list').append('<li>' + "Holi1" + '</li>');
    });
});