Kweldulf Kweldulf - 6 months ago 19
jQuery Question

.slice() is not a function although called on string

I'm trying to figure out some collision, but the compiler keeps showing the error that .slice() is not a function. Here is the code:

var topPos1 = $('#player').css("top");
var rightPos1 = $('#player').css("right");
var topPos2 = $('#player').css("top");
var rightPos2 = $('#player').css("right");
var pos = topPos1.indexOf('px');
topPos1 = parseInt(topPos1.slice(0,pos));


My jQuery is loaded.

Answer

Maybe your topPos1 return nothing, if the $('#player') has no css value for top, assigning it to a value will result null or NaN.

You should use log the values to see if the result are correct.

Comments