May 28, 2010

How do i hide html until its processed with javascript?

Question by acidzombie24

I am using some JS code to transform my menu into a drilldown menu.

The problem is before it runs the JS you see a BIG UGLY mess of links. On their site its solved by putting the js at the top. Using recommendations by yahoo/YSlow i am keeping the JS files at the bottom.

I tried hiding the menu with display:none then using jquery to .show(), .css(‘display’, ”), .css(‘display’, ‘block’) and they all lead up to a messsed up looking menu (i get the title but not the title background color or any links of the menu)

How do i properly hide a div/menu and show it after being rendered?

Answer by acidzombie24

I found the solution. I should let the links be hidden with css then .show() BEFORE the ddMenu code executes instead of after. The ddMenu seems to check the parents width and sinces its hidden i guess its 0. The time between .show() and ddMenu is fast enough not to show the ugly links (on my machine/browser). The the majority of the time (page loading, http req for the JS files, JS compiling/exec etc) the links are hidden so it looks pretty good.

$(function () {
    $('.menuT1').show(); //do it before not after in this case.
    $('.menuT1 > ul').ddMenu({

Answer by Starx

Well, If you are familiar with jquery then I would do something like this

$("#mybuttom").click(function() {
           $("#mydiv").hide(); //hide the div at the start of process
           $.post( "mypostpage.php", 
                   { testvar: testdata },
                   function(data) {
                         //callback function after successful post
                         $('#mydiv').show(); //show it again
                   }
           );
});

Author: Nabin Nepal (Starx)

Hello, I am Nabin Nepal and you can call me Starx. This is my blog where write about my life and my involvements. I am a Software Developer, A Cyclist and a Realist. I hope you will find my blog interesting. Follow me on Google+

...

Please fill the form - I will response as fast as I can!