JavaScript error: Uncaught SyntaxError: missing ) after argument list


#1

i dont know were to ask general jquery questions so ill do it here



<script src="//ajax.googleapis.com/ajax/libs/jquery/3.1.0/jquery.min.js"></script>
<img src="http://convertico.com/images/59e6ddda777b6/_previmg.png">
<div>
<script>
$(document).on("mousemove",function(event){
  $('div').text(event.pageX + " " + event.pageY);
  const mouseX = event.pageX
  const mouseY = event.pageY
});
$('img').css('margin' 'absolute '+'mouseX'+'px');
</script>



i am trying tho get the img element to follow the mouse’s x using $(jquery).pageX but i am getting this error.
the problem seems to be in the $(‘img’.css) line


#2

looking at the css documentation:

http://api.jquery.com/css/

setting multiply properties takes a dictionary (from documentation):

.css({ "background-color": "#ffe", "border-left": "5px solid #ccc" }) 

if the background-color is then stored in a variable, you can simply do:

.css({ "background-color": backgroundColorVariable, "border-left": "5px solid #ccc" }) 

nice and simple.

not sure what you currently do, margin is a property, absolute is a value, but of position


#5

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.