I have some trouble to hide some div in my application, this code is used in jQuery UI ta开发者_JS百科bs.
In the controller :
public ActionResult MyAction()
{
return View("MyView", model);
}
In the view "MyView", I have this :
<script type="text/javascript">
$(document).ready(function () {
$('#divToHide1').hide();
$('#divToHide2').hide();
});
</script>
<div id="divToHide1">
</div>
<div id="divToHide2">
</div>
The problem the div are never hidded, any idea ?
Thanks,
Update1 : when I switch to second tab, I do the prcedure below. The switch to thez tab is ok, I receive an "alert1", and I receive "1" correspondinf to the length, but the div is still visible.
function e2() {
var jqxhr = $.post("/Controller/MyAction", function (data) {
$('#tabs-2').html(data);
})
.success(function () {
alert('alert1');
})
.error(function () { })
.complete(function () {
alert($('#divToHide1').length);
$('#divToHide1').hide();
});
}
Update2 : I tried with class instead of id ... and look ok
Do this in CSS:
.ui-tabs-hide {
display: none;
}
If you're using jQuery UI Tabs, it will append classes to your elements. All your inactive views will have css class "ui-tabs-hide".
What you have written there should work. Have you tried .toggle or binding the action to a link/button opposed to on document load, see if that helps. You do have Jquery included?
I use $(". and not $("# as selector, it's strange but that's work
精彩评论