0

I have the following HTML

<div class="col-lg-4 col-md-4 col-sm-3">
  <div class="thumbnail">
     <img src="http://res.Domain.com/dncu6pqpm/image/upload/q_80,c_fill,h_200,w_320/ImageName.jpg">
    <div class="caption">
        <p align="center">
          <input id="IsProfilePic" class="btn btn-primary btn-block profilebutton" type="button" value="Profile Picture" data-id="1">
       </p>
        <p align="center">
          <input id="IsDelete" class="btn btn-danger btn-block deletebutton" type="button" value="Delete Picture" data-id="1">
       </p>
   </div>
  </div>
</div>

When the user clicks profileButton I call the following jquery which calls the db, when it returns I want to change the thumbnail background color to yellow so it notifies the user as follows:

$('.profilebutton').on("click", function () {
            $.ajax({
                url: 'Url for method',
                data: { "pictureId": $(this).attr("data-id") },
                cache: false,
                type: "GET",
                success: function (result) {
                    alert('here');
                    $(this).closest("div.thumbnail").css("background-color", "yellow");

                },
                error: function (result) { }
            });

            return false;
        });

but i see the alert message but the background does not change and remains white, can someone please tell me what I'm doing wrong here ?

Code Ratchet
  • 5,758
  • 18
  • 77
  • 141
  • @Barmar That's javascript stopwatch question not sure what that has to do with setting the background image? – Code Ratchet Apr 14 '15 at 11:31
  • 2
    The problem is that `$(this)` doesn't do what you think it does in the callback. Fix that just as in the other question. – Barmar Apr 14 '15 at 11:32
  • 2
    put `$this = $(this);` before ajax , in the ajax success use `$this.closest("div.thumbnail").css("background-color", "yellow");` – madalinivascu Apr 14 '15 at 11:33

0 Answers0