1
$('.editTime').click(function(){
            var thisId = $(this).closest('td').attr('id');
            alert($('#'+thisId).html());
            $('#'+thisId).html("Some Text");
            alert($('#'+thisId).html());
    });


 <td class='editTime' id='someId'><a href='#'>Some Original Text</a></td>

When a user clicks the link in the td, the data in the cell should change from "Some Original Text" to "Some Text". In the browser window it does not change. The alerts however do show the new data in the cell. Any idea whats going on here?

3
  • 1
    use $(this).attr('id'); with $('#'+thisId).find('a').html("Some Text"); Commented Oct 17, 2017 at 6:11
  • or try direct $(this).find('a').text('Some Text); simply Commented Oct 17, 2017 at 6:13
  • $('.editTime').click(function(){ ... but your <a> is not $('.editTime'), that's your <td> :/ so it's not the jQuery which is odd, it just you're being not careful Commented Oct 17, 2017 at 6:35

3 Answers 3

2

Try

$('.editTime').click(function(){
    $(this).find('a').text("Some Text");
});
Sign up to request clarification or add additional context in comments.

Comments

0

<!DOCTYPE html>
<html lang="en">
<head>
    <title>Bootstrap Theme Simply Me</title>
    <meta charset="utf-8">
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
    <script type="text/javascript">
        $(document).ready(function () {
            $('#someId').on('click', function () {
                $('#someId a').text('Some Text');
            });
        });
    </script>
</head>
<body>
    <table>
        <tr><td class='editTime' id='someId'><a href='#'>Some Original Text</a></td></tr>
    </table>
</body>
</html>

Comments

0

I think that when you click on the td, a tag is also being clicked so you have to use e.preventDefault() function to prevent the page to load again.

So the code can be written like this

$('.editTime').click(function(e){
 e.preventDefault();
 $(this).find('a').html('Some text')
})

HTML should contain proper table and tr tags.

For example

<table>
  <tr>
    <td class='editTime' id='someId'><a href='#'>Some Original Text</a></td>
  </tr>
</table>

Check the working fiddle here.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.