Pregunta

hi this is my html code :

<div class="transe_row">
    <div class="litransa1" style="cursor:pointer;">Servicii programare Transa 1</div>
    <div class="litransa suma" style="cursor:pointer;"> Adauga Suma</div>
    <input type ="text"   placeholder ="adauga suma transa" style ="display:none;">
</div>

and this is my js :

<script type="text/javascript">
    $(document).ready(function (){
            $(".litransa.suma").click(function() {
                 $('.litransa.suma').find(closest('input')).css("display","inline");
        });
    });
</script>

I just want to change the the css from the input by clicking the .listransa.suma class. Why my code doesn't work ?thx

¿Fue útil?

Solución

You need to use .siblings() for finding sibling elements:

 $(document).ready(function () {
  $(".litransa.suma").click(function () {
     $(this).siblings('input').css("display","inline")
  });
});

Otros consejos

.next() and this keyword

$(document).ready(function () {
    $(".litransa.suma").click(function () {
        $(this).next('input').css("display", "inline");//or $(this).next('input').show();
    });
});

this refer to the current element clicked

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top