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

有帮助吗?

解决方案

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

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

其他提示

.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

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top