When adding an error message, you must first clear the div
My HTML looks like this and js looks like this:
<div class="container"></div>
var html = "<div class="error">hello</div>";
$(".container").append( $(html) );
The problem is that I do not clear the html inside the div with class = container at first, so I keep adding posts to this area.
How can I clear the entire contents of a container div class = "and THEN add my 'html' div?
Assuming you want to “replace” with what's in your div, I think you need to use:
$(".container").html( html );
More jQueryish way to do this:
$errorDiv = $('<div>hello</div>').addClass('error');
$(".container").html($errorDiv.html());
This has the added benefit of giving you a link to a div error.
, , / " ", div. , :
Html:
<div id="status"></div>
JavaScript:
function showError(msg) {
$('#status').html(msg).addClass('error');
}
function showStatus(msg) {
$('#status').html(msg).removeClass('error');
}
:
- ,
<div>id-, javascriptdocument.getElementById(), , DOM ... <div class="container">, . html css div. =)- You obviously do not need the message status / error message logic in separate methods - I did this just for clarity.