I have a bunch of buttons nested in div tags in my html
<div class="button-wrapper"> <button class="button-class">Click here</button> </div> <div class="button-wrapper"> <button class="button-class">Click here</button> </div> ...
By clicking the button, you can send some data using jQuery and return the HTML code through the .ajax success function. I am trying to replace the contents of a div for every button I clicked, but for some reason my jQuery selector does not seem to work.
I am trying to execute the following function:
$(this).parent().html(data);
I know that data is sent successfully and that the success function works. What is strange is that the following works:
$(".button-wrapper").html(data);
but obviously this adds HTML for each div, and not just for the button that is clicked.
Does anyone know where I can go wrong here?
source share