2 Replies - 317 Views - Last Post: 28 March 2018 - 06:33 AM

#1 Foobarer   User is offline

  • D.I.C Regular

Reputation: 1
  • View blog
  • Posts: 269
  • Joined: 28-March 17

How to change text of sibling of clicked button?

Posted 28 March 2018 - 04:30 AM

I have the following:
<div>
    <span class="updated_text"> Hello </span>
    <button class="update_me">
</div>

 $('.update_me').click(function (e) {
                e.preventDefault();
                var value = $(this).siblings('input').val(); // get value from hidden input - this one works!          
                $.post("update.php", {id: value})
                        .done(function (data) {
                        $(this).siblings(".updated_text").text(data); // doesn't work
                        });
            });




This post has been edited by Foobarer: 28 March 2018 - 04:32 AM


Is This A Good Question/Topic? 0
  • +

Replies To: How to change text of sibling of clicked button?

#2 Dormilich   User is online

  • 痛覚残留
  • member icon

Reputation: 4230
  • View blog
  • Posts: 13,411
  • Joined: 08-June 10

Re: How to change text of sibling of clicked button?

Posted 28 March 2018 - 04:53 AM

the this inside the done() callback is not the same this as in the event listener.
Was This Post Helpful? 1
  • +
  • -

#3 Foobarer   User is offline

  • D.I.C Regular

Reputation: 1
  • View blog
  • Posts: 269
  • Joined: 28-March 17

Re: How to change text of sibling of clicked button?

Posted 28 March 2018 - 06:33 AM

Thank you!
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1