I have a jquery mouseover event which succesfully calls a javascript function
$(document).ready(function() {
$('.nw').mouseover(run_nw);
});
function run_nw() {
...
}
However, when I try to pass parameters, the js fails.
$(document).ready(function() {
$('.nw').mouseover(run_nw(1));
});
var a;
function run_nw(a) {
...
}
Tried looking through SO and through jQ documentation but I'm still stumped. I'm assuming this is a simple formatting issue.
Thanks
(Here is the full code if it helps)
<script>
var $ = jQuery.noConflict();
var incr = 650;
function run_nw() {
//move x and y
var topAdjust = -incr;
var leftAdjust = -incr;
var top = parseInt($(this).css('top'))+topAdjust;
var left = parseInt($(this).parent().css('left'))+leftAdjust;
//rotate
var randomnumber = Math.floor(Math.random()*11);
var rotate = -randomnumber*10;
$(this).animate({
top:top,
left:left,
'rotate':rotate
}, 700, 'swing');
}
$(document).ready(function() {
$('.nw').mouseover(run_nw);
});
</script>
parseIntyou should pass the number 10 as a second parameter. If you don't, then funky things can happen. If you're number starts with a zero, for example, I think JS interprets it as hex and uses base 16.