0

I have some trouble to hide some div in my application, this code is used in jQuery UI tabs.

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

4
  • Just to confirm - you're including jQuery into your HTML above the document.ready, yeah? Commented Apr 7, 2011 at 8:29
  • Are you getting any errors appearing in the console? Commented Apr 7, 2011 at 8:31
  • The divs you're trying to hide - are they appended to the document though jQuery after document load? Commented Apr 7, 2011 at 9:24
  • @Rory yes, when I click on the tab > controller > return a view and the div to hidden are on this view. I tried to place jquery here and other places no success Commented Apr 7, 2011 at 9:28

3 Answers 3

1

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".

Sign up to request clarification or add additional context in comments.

Comments

0

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?

1 Comment

I have x tabs (jQuery UI tab). When I switch tab some part are not visible on the tabs and are display depending of a dropdown value
0

I use $(". and not $("# as selector, it's strange but that's work

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.