0
function slide(var) {

     if ( parseInt( var.css('marginLeft') ) >= -2160 ){

        var.animate({'margin-left': '-='+width}, animationSpeed, function() {
        });

      }

}

onclick='(document.getElementById('slides'))'

How can I make this function work by replacing the function parameter (var) with the div slides id?

Zoe stands with Ukraine
  • 25,310
  • 18
  • 114
  • 149
  • 3
    `onclick` is not a jQuery thing. Also `var` is a special word in javascript. While this is not a syntax error, it could very easily lead to a logical error. – Taplar May 24 '18 at 19:01
  • You are also not invoking the slide method in your onclick, but even if you were, `var` is a DOM Element ( document.getElementById('slides') ), not a jQuery object. You will need to wrap it in `$()` if you want to use the `animate()` method which is a jQuery method. Same issue is present for the `css()` method. – Taplar May 24 '18 at 19:03
  • `onclick='slide(document.getElementById(\'slides\'))'` – Kevin B May 24 '18 at 19:12

1 Answers1

0

Use jQuery to bind the handler. Inside the jQuery handler, this is the target element.

$("#slides").click(function() {
    slide($(this));
}
Barmar
  • 669,327
  • 51
  • 454
  • 560