Open different elements js

0

I would like to know how I can create a function in JS / Jquey that opens a DIV that not is visible.

However, I will have more than one DIV, and I need JS to identify these DIVs (I hope it was clear) rs !!

Obs : My code is a slider and when you click on a certain image of the slider it will open this DIV with some information.

    
asked by anonymous 24.03.2016 / 15:45

1 answer

0

With Jquery it would look something like this:

1 - assign a class and attribute 'date' to the image / slide that will open the div and also the same id in the div that you would like to open with the click and make the following code:

<img class="classeImagem" src="caminho" data-alvo="idDaDivAberta01">
<div id="idDaDivAberta01">

2 - Pass in as the parameter to the function the Div id you want to open.

$('.classeImagem').click(function(){
   var id = '#'+$(this).data('alvo');
   //mostrando a div
   toggleDiv(id);
   //se quiser fechar alguma que já esta aberta é só fazer verificador
});

// the function would look something like this:

function toggleDiv(id){
    //verifica se o elemento já aberto não é o mesmo do clicado
    if($(id).hasClass('aberta') == false){
        $('.classeEmComum').fadeOut(700).removeClass('aberta');
        $(id).fadeIn(700).addClass('aberta');
    }
}

I hope I have helped, you can assign the '#' character in the value of the date attribute too, although it is not a good practice. Remember to add a common class in the div's that will handle, and add the class in the first element that will already be open.

    
24.03.2016 / 16:10