javascript - TypeError: invalid 'in' operand a in a class -
have javascript code here uses jquery create class , use class functions then.
function sample(a, b) { var id = a; var img_src = b; this.getid = function() { return id; }; this.move = function(ptop, pleft) { var p = $(this).position(); var mov_top = p.top + ptop; var mov_left = p.left + pleft; $(this).animate({ top: mov_top, left: mov_left }); } } and calling when clicking button :
<button onclick="create(3);">click me :d</button> <script> function create(id) { var mysample = new sample(id, 'url'); mysample.move(50, 50); } </script> and returns me error typeerror: invalid 'in' operand don't see comes from...
do has idea?
try passing this create() instead of 3 should a within sample() , setting button css position relative
function sample(a, b) { var id = a; var img_src = b; this.getid = function() { return id; }; this.move = function(ptop, pleft) { var p = $(a).position(); var mov_top = p.top + ptop; var mov_left = p.left + pleft; $(a).animate({ top: mov_top, left: mov_left }); } } button { position:relative; } <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"> </script> <button onclick="create(this);">click me :d</button> <script> function create(id) { var mysample = new sample(id, 'url'); mysample.move(50, 50); } </script>
Comments
Post a Comment