Problem with CSS in Jquery

1

I have the following HTML:

$(".membrosClick").click(function() {
  $(".membrosClick").css("width", "766px");
  $(this).children().fadeToggle();
  $(".listagemEsc").css("margin-left", "383px");
});
<li class="membrosClick">
  <div name="Listagem de Membros" style="background-image: url('./imagens/EDGAR-GUERRA.png'); width:383px; height:849px">
    <div class="editable subir">
      <h2>Edgar</h2>
      <h3>Guerra</h3>	
      <div class="bandaBarra bandaBarraBranca margin-left-65 margin-top-10 barraNone"></div>
    </div>

  </div>
  <div class="listagemEsc p-relative">
    <div class="membrosFechar"></div>
    <span>Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum. Sed ut perspiciatis unde omnis iste natus error sit voluptatem accusantium doloremque laudantium, totam rem aperiam, eaque ipsa quae ab illo.</span>
  </div>
</li>
<li class="membrosClick">
  <div name="Listagem de Membros" style="background-image: url('./imagens/ANTONIO-GUERRA.png'); width:383px; height:849px">
    <div class="editable subir">
      <h2>Antônio</h2>
      <h3>Guerra</h3>	
      <div class="bandaBarra bandaBarraBranca margin-left-65 margin-top-10 barraNone"></div>
    </div>

  </div>
  <div class="listagemEsc p-relative">
    <div class="membrosFechar"></div>
    <span>Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum. Sed ut perspiciatis unde omnis iste natus error sit voluptatem accusantium doloremque laudantium, totam rem aperiam, eaque ipsa quae ab illo.</span>
  </div>
</li>

When I click on li it has to expand it to width: 766px and send div listagemEsc to margin-left:383px . It is expanding to 766px only that it does this in all li , not just the one I clicked on. With that I could not test the rest.

    
asked by anonymous 12.03.2015 / 21:37

1 answer

1

Two changes:

  • use $(this).css() to only apply to the element you clicked
  • uses .next() to get the brother div immediately following, instead of calling all elements with the listagemEsc class in the selector. Or to be more specific el.closest('.membrosClick').find('.listagemEsc').css("margin-left", "383px");

Final result:

$(".membrosClick").click(function () {
    var el = $(this);
    el.css("width", "766px");
    el.children().fadeToggle();
    el.next().css("margin-left", "383px");
});
    
12.03.2015 / 21:39