I'm not sure what the code surrounding your code looks like,
but from the code below, it looks like you're missing a ")"
at the end to close the first "(" after .hover ...

This should work:

$(".button").hover(function() {

   $(".button").addClass("imgbuttonhover");
   $(".button").removeClass("imgbutton");

   }, function() {

   $(".button").addClass("imgbutton);
   $(".button").removeClass("imgbuttonhover);

   }
)

The code above, I guess, is surrounded by $(document).ready(function() { ?
As in:

$(document).ready(function() {

   $(".button").hover(function() {

      $(".button").addClass("imgbuttonhover");
      $(".button").removeClass("imgbutton");

   }, function() {

      $(".button").addClass("imgbutton");
      $(".button").removeClas("imgbuttonhover");

      }
   )
});

A few observations about the code above that might be helpful...

- consider using an ID for the button instead of a class, say, "myButton"
  (Unless for some reason you have multiple buttons you want to rollover
  at the same time)

- then use two classes to swap the img: .button and .buttonHover

- also, after the first reference to the button in the second line above,
  you can refer to the button as "this", which according to my understanding
  will speed up jQuery's reference to the button, keeping it from having to
  search the DOM for a match by having a "ready reference" to it by using
"this"

The code would then look like this:

(A div used for the rollover, would work like this using color instead of an
img)

HTML:

   <div id="myButton" class="button"></div>

CSS:

   .button { background:#abc; width:50opx; height:50px; }
   .buttonHover { background:#def; width:50px; height:50px; }

JQUERY:

$(document).ready(function() {

   $("#myButton").hover(function() {

      $(this).removeClass("button");
      $(this).addClass("buttonHover");

   }, function () {

      $(this).removeClass("buttonHover");
      $(this).addClass("button");

      }
   )
});

Of course, to use images for the rollover, just modify the CSS.

hth,

Rick

   


-----Original Message-----
From: jquery-en@googlegroups.com [mailto:jquery...@googlegroups.com] On
Behalf Of jessie
Sent: Saturday, October 10, 2009 9:03 PM
To: jQuery (English)
Subject: [jQuery] My code is not working getting an error missing )


Hi Everyone

I have been given this code to add to my effects.js
$(".button").hover(function() {
$(".button").addClass("imgbuttonhover");
$(".button").removeClass("imgbutton");
}, function() {
$(".button").addClass("imgbutton");
$(".button").removeClass("imgbuttonhover");
}

But when i add it to my file i get this error via firefox.

missing ) after argument list
[Break on this error] }\n

Can someone please tell me what i'm missing?

Thank-you.

Jess


Reply via email to