Toggle in a div next to (or below)

Asked

Viewed 286 times

0

I need to manipulate a div from the click on another div.

Basically, one is on top of the other, I want to click the top one and so the bottom one runs the event .toggled(). But one cannot be inside the other.

HTML

<div id="titulo" class=" toggled " align="left">Histórico</div>
<br>
<div id="divTabela">
    <table id="tabelainfo" name="tabelainfo" class=" bordasimples ">
    <thead>
    <tr id="titulotabela">
        <th>Data</th>
    </thead>
    <tbody>
    <tr id="corpotabela">
        <td align="center">15/5/2014 </td></tr>
    <tr id="corpotabelaalt" align="center">
        <td align="center">16/5/2014 10:56:10</td></tr>
    <tr id="corpotabela">
        <td align="center">16/5/2014 11:00:28</td></tr>
    </tbody>
    </table>
<br><br></div>

Javascript

$("*").on("click", ".toggled", function(event){
    event.preventDefault();
    event.stopPropagation();

    console.log($(this));
    $(this).css({"color":"red","border":"2px solid red"});
    $(this).next("div").toggle();
});

Jsfiddle

What you suggest to me?

2 answers

3


$('#elemento-de-clicar').click(function(){
    $('#elemento-alvo').slideToggle();
 });
  • Enter the. next() between selector and slideToggle() so your answer will be correct, as well as the new Fiddle where I inserted the correction from your suggestion: http://jsfiddle.net/mayconfsbrito/2kLpu/4/

  • I forgot the . next(). Thank you so much for pointing out rs.

0

<!-- HTML -->    
<p class="linkToggle">
   <strong><span>[+] </span>Detalhamento dos Pacotes de Serviços</strong>
</p>
<div class="lista forToggle">
    olá mundo!
</div>
<!-- HTML -->


<script>
       $('.linkToggle').click(function () {
             $(this).next(".forToggle").toggle('slow', function () { });
             var val = $(this).html();
             if (val.indexOf("[+]") > -1)
                  $(this).html(val.replace("[+]", "[-]"));
             else
                  $(this).html(val.replace("[-]", "[+]"));
        });
</script>
  • Click on the class ". linkToggle" and apply the animation to the next element with the class ". forToggle".

Browser other questions tagged

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