There is such a piece of code:

$( ".left" ).click(function() { event.preventDefault(); $(".slideritems").css("margin-left", "-268px"); }); 

When you press the button, the whole div should move to the left by 268px, but not one-time, but each time, when you press further and further. Tell me how to implement it? something I can not find the answer anywhere

    1 answer 1

    With the markup it would be easier, but it will do as well:

     let currentDisplacement = 0; $('.left').click(() => { currentDisplacement -= 268; console.log(currentDisplacement); $('.slideritems').css('margin-left', currentDisplacement); }); 
     .slideritems { height: 10px; width: 100%; background-color: red; } 
     <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <div class="container"> <div class="slideritems"></div> </div> <button class="left">Click</button>