If you know it's always going to be an "a" element, maybe this would work:

switch (event.target.className) {
   case 'close':
       do stuff
       break
   case 'continue':
       do stuff
       break
etc.

-- Josh



----- Original Message ----- From: "gr00vy0ne" <[EMAIL PROTECTED]>
To: "jQuery (English)" <jquery-en@googlegroups.com>
Sent: Thursday, September 06, 2007 11:08 AM
Subject: [jQuery] event.target and switch statement...



Newbie question...

Does the switch statement work with event.target?

For instance, I have the following condition in my script:

if ($(event.target).is("a.close") {
  $("#popup_layer").hide(); }
else if ($(event.target).is("a.continue") {
  // do something else }
...

I actually have a few more conditions that look for specific anchor
classes to do different stuff. I'm thinking it would be nicer to move
to a switch statement but my code doesn't seem to work. I suspect I'm
doing something wrong. What is the proper way of converting the above
to a switch statement? Here's what I'm doing so far...

switch ($(event.target)) {
  case "a.close":
  $("#popup_layer").hide(); }
  break;
  case "a.continue":
  $("#popup_layer").hide(); }
  break;
...
}

I know $(event.target) is an object so it can't equal any of the cases
but I'm unsure what the proper syntax is to get the value out of the
initial condition.

Thanks for any guidance.
-v

Reply via email to