SitePoint Sponsor

User Tag List

Results 1 to 5 of 5
  1. #1
    SitePoint Guru team1504's Avatar
    Join Date
    May 2010
    Location
    Okemos, Michigan, USA
    Posts
    732
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)

    unexpected token / character

    Hi guys,
    I was trying to apply the animation of sliding up by applying a less margin in javascript, but it is saying that my margin can not be negative err or what the error actually says is that the negative symbol - is an unexpected token.
    Here is my code:
    Code JavaScript:
    <script type="text/javascript">
    	$("#followMe").hover(
      		function () {
        		$("#followMe").animate({margin-top:-128}, 600);
      		}, 
      		function () {
       			$("#followMe").animate({margin-top:-113}, 600);
      		}
    	);
    </script>

    I was hoping that someone could help me fix?
    Is there an escape character or something that I can use?

    Thanks in Advance and I hope to hear from you soon,
    Team 1504.

  2. #2
    SitePoint Wizard
    Join Date
    Dec 2003
    Location
    USA
    Posts
    2,582
    Mentioned
    29 Post(s)
    Tagged
    0 Thread(s)
    Try specifying it as "-113px" instead of -113 (including quotation marks).

  3. #3
    SitePoint Guru team1504's Avatar
    Join Date
    May 2010
    Location
    Okemos, Michigan, USA
    Posts
    732
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    thank you for replying quickly.

    Unfortunately, Chrome still says that there is an Unexpected Token Error for '-' even with the quotation marks.
    Here is the code in case you can think of any other solutions:
    <script type="text/javascript">
    $("#followMe").hover(
    function () {
    $("#followMe").animate({margin-top:"-128"}, 600);
    },
    function () {
    $("#followMe").animate({margin-top:"-113"}, 600);
    }
    );
    </script>

    Thanks in Advance,
    Team 1504

  4. #4
    SitePoint Wizard
    Join Date
    Dec 2003
    Location
    USA
    Posts
    2,582
    Mentioned
    29 Post(s)
    Tagged
    0 Thread(s)
    ... duh. After looking at the code more closely I realized it's the - in margin-top that's causing the issue, not the one on the number.

    You need to do "margin-top".

    You also need to put px with your number. It's different from style.marginTop. It's the same as when you do regular CSS, you can't omit px.

    Javascript maps need to be done like {"key": "vlaue"}.

  5. #5
    SitePoint Guru team1504's Avatar
    Join Date
    May 2010
    Location
    Okemos, Michigan, USA
    Posts
    732
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    Thank you very much! That worked perfectly


Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •