Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    New Coder
    Join Date
    Mar 2012
    Posts
    60
    Thanks
    65
    Thanked 0 Times in 0 Posts

    change text of third td span

    Hi

    I am not able to add any type of ID or class so with this in mind:

    How do I change the word "changeMe" to "textEDITED" relative to its own "tr" from the edit click






    Code:
    <script>
    function changeText(){
        $(this).parent().find("td:eq(3)").find("span").text() = "textEDITED";
    }
    </script>
    
    
    
    
    <table>
    
       <tr>
        <td><span onclick="changeText()">edit</span></td>
        <td>test</td>
        <td>test</td>
        <td><span >changeMe</span></td>
       </tr
       
       <tr>
        <td><span onclick="changeText()">edit</span></td>
        <td>test</td>
        <td>test</td>
        <td><span >changeMe</span></td>
       </tr
       
       <tr>
        <td><span onclick="changeText()">edit</span></td>
        <td>test</td>
        <td>test</td>
        <td><span>changeMe</span></td>
       </tr>
       
    </table>

  • #2
    Senior Coder Spudhead's Avatar
    Join Date
    Jun 2002
    Location
    London, UK
    Posts
    1,856
    Thanks
    8
    Thanked 110 Times in 109 Posts
    You don't need (and shouldn't have) the onclick as an HTML attribute.

    (using jQuery 1.7.2):
    Code:
    ​$(function(){
        $('td:nth-child(1) span').on('click', function(){
            $(this).parents('tr').find('td:eq(3) span').text('textEDITED');
        }); 
    });


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •