Show or hide div element using jQuery
I am new to jquery
and I am trying to hide a certain element div
and then show them the success of my call Ajax
. When the page loads, the browser hides the element div
, on Ajax
success, the element is displayed, but again the browser hides the elements div
.
Code
<script>
$(document).ready(function() {
$('#sidebar-container').hide(1000);
$('#overall-status').hide(1000);
$('#submit-date').click(function() {
var processDate = $('#processDate').val();
alert(processDate);
$.ajax({
type : "POST",
url : "launchapptest",
data : processDate,
dataType : "json",
success : function(result) {
alert("Success");
$('#sidebar-container').css({
visibility : "visible"
});
$('#overall-status').css({
visibility : "visible"
});
}
});
}
);
});
</script>
Please help me understand what is happening and how to avoid it.
source to share
You must first stop the current animation queue for each element (since non-animated CSS changes will not be added to this queue):
Also, as mentioned elsewhere show()
, this is a better option for css visibility
as hidden sets display: none
rather than visibility
.
success : function(result) {
alert("Success");
$('#sidebar-container').stop().show();
$('#overall-status').stop().show();
}
Also, you can keep the form submitting, so the page will reload and display the div. Try to stop this button's default behavior.
$('#submit-date').click(function(e) {
e.preventdefault()
source to share
Use jquery event Show
.
$(document).ready(function() {
$('#sidebar-container').hide(1000);
$('#overall-status').hide(1000);
$('#submit-date').click(function() {
var processDate = $('#processDate').val();
alert(processDate);
$.ajax({
type : "POST",
url : "launchapptest",
data : processDate,
dataType : "json",
success : function(result) {
alert("Success");
$('#sidebar-container').show();
$('#overall-status').show();
}
});
}
);
});
source to share