Question

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

Was it helpful?

Solution

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

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

OTHER TIPS

.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

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top