Divs being added on top of each other

Asked

Viewed 360 times

3

I have three menus, when I click on each one, it leaves a div that was like display:none as display:block. What is happening is that your clicking on Menu 1 and then on Menu 2, it is adding a div at the bottom of the other.

Jquery is like this:

$( "#dadosTecnicos" ).click(function() {
    $( "#mostrarDadosTecnicos" ).fadeToggle( 'fast', function() {});
});

$( "#galeria" ).click(function() {
    $( "#mostrarGaleria" ).fadeToggle( 'fast', function() {});
});

$( "#downloads" ).click(function() {
    $( "#mostrarDownload" ).fadeToggle( 'fast', function() {});
});

For example: by clicking on id data he shows the div mostrarDadosTecnicos if after I click on galeria, the mostrarGaleriawill stay under mostrarDadosTecnicos.

Example in Jsfiddle

  • 3

    Could you do it on http://jsfiddle.net/

  • Of course. It looks like this: http://jsfiddle.net/felipestoker/2NNe8/

1 answer

2


What’s happening is that when you exhibit one you forget to disappear the other two

in the example below I used the .hide() at a glance here

Code

$( "#dadosTecnicos" ).click(function() {
    $( "#mostrarDadosTecnicos" ).fadeToggle( 'fast', function() {});
    $( "#mostrarGaleria" ).hide();
    $( "#mostrarDownload" ).hide();
});

$( "#galeria" ).click(function() {
    $( "#mostrarGaleria" ).fadeToggle( 'fast', function() {});
    $( "#mostrarDownload" ).hide();
    $( "#mostrarDadosTecnicos" ).hide();
});

$( "#downloads" ).click(function() {
    $( "#mostrarDownload" ).fadeToggle( 'fast', function() {});
    $( "#mostrarGaleria" ).hide();
    $( "#mostrarDadosTecnicos" ).hide();
});
  • 1

    Silvio, thank you very much man. It worked 100% P

  • @Felipestoker was worth ;)

  • If by chance I wanted to add a CSS, when the person clicks on a specific menu, he applies a color ('blue' for example) and changes the color of others. You would tell me to use .css informing the rules, or .addClass creating a class for it?

  • CTRL + C | CTRL + V

  • 3

    @Felipestoker I believe using .addClass would be more organized but I use the .css for being much more practical and also end up saving code, in the case of .addClass it is used more for large classes for example with 10 css properties, in the case of one or even two the best is to use the .css

Browser other questions tagged

You are not signed in. Login or sign up in order to post.