</div>
</div>
<div class="grid--cell mb0 mt4">
<a href="/questions/13822322/jquery-how-to-clear-an-element-before-appending-new-content" dir="ltr">Jquery: How to clear an element before appending new content?</a>
<span class="question-originals-answer-count">
(4 answers)
</span>
</div>
<div class="grid--cell mb0 mt8">Closed <span title="2020-03-07 17:36:39Z" class="relativetime">last month</span>.</div>
</div>
</aside>
I've recently started using and learning JS and jquery. I'm sending a user email from a form to my PHP page to check if any user exists in DB via ajax, then I get a response from my PHP file if the user exists or not and display the text in a div. It's working fine, but because the page doesn't refresh when the button for sending form data is pressed, ajax just stacks the response from PHP.
I probably need to clear the response every time the button is clicked first and then append the response but I can't find the right command for it :/
JS
function sendnewpass() {
var email = document.getElementById("useremail").value;
$.ajax({
type : "POST",
url : "login.php", //my php page
data : { passemail : email }, //passing the email
success: function(res){ //to do if successful
$("#emailsentmsg").append(res); //the the div that i put the response in
}
});
}
</div>