Why is jQuery code sometimes used in window.load?

I am trying to hide a div that was dynamically added with accordion.js at runtime, but it is hiding somewhere and sometimes not.

Here is my code:

function hideTab2() {
  $(window).load(function(){
    $("#myaccordian-accordion").find('.panel ').eq(1).addClass('hidden');
    $("#myaccordian-accordion").find('.panel ').eq(2).addClass('hidden');
  });
}

      

hideTab2()

function call from codebehind.

+3


source to share


1 answer


You should try this, it gets called after your page is fully rendered.

$(window).bind("load", function () {
    $("#myaccordian-accordion").find('.panel ').eq(1).addClass('hidden');
    $("#myaccordian-accordion").find('.panel ').eq(2).addClass('hidden');
});

      



As discussed with the questioner,

<head runat="server">
<title></title>

<% if(Request.QueryString["status"] == "add") { %>
    $(window).bind("load", function () {
        $("#myaccordian-accordion").find('.panel ').eq(1).addClass('hidden');
        $("#myaccordian-accordion").find('.panel ').eq(2).addClass('hidden');
    });
<%} %>

</head>

      

+1


source







All Articles