Old 20-07-2009, 15:20   #1 (permalink)
sarajs
Senior Member
 
sarajs's Avatar
 
Join Date: Jun 2007
Location: London
Posts: 809
Send a message via MSN to sarajs
JQuery Switch Statement

So,
a) Can you do a switch statement in JQuery
b) Would there be a more effective way to do it.

I have 29 different images and each image has a seperate bit of blurb, when I click on the image it gets bigger, then I want to produce the correct blurb for it. I'm not sure if I'm writing the switch statement wrong or not?!

Code:
<script type="text/javascript"> $(document).ready(function () { $("div.scrollable").scrollable(); $("div.scrollable div.items div img").click(function() { $(this).fadeOut().fadeIn(); var dots = ".."; var fname = $(this).attr("src").match(/[^\.]+/); var src = dots + fname + "Large.jpg"; var caption = "your text here"; switch(fname) { case 'personame1': caption = "blurb1"; break; case 'personame2: caption= "blurb2"; break; default: caption ="default"; } $(#"caption").html(caption); $("#fullsizepicture img").attr("src",src); $("#block").toggle(); $(".sortPadding").toggle(); $("#caption").html(fname); }); $("#ImageClose").click( function(){ $("#block").toggle(); $(".sortpadding").toggle(); }); }); </script>
__________________
  Reply With Quote
Old 20-07-2009, 15:44   #2 (permalink)
funkyprem
For all your goober needs
 
funkyprem's Avatar
 
Join Date: Dec 2004
Location: Coventry, UK
Posts: 1,823
I don't get what you're trying to aceieve here Sara.

Also from my initial read, your functions aren't closed off properly.

Code:
$(document).ready(function () { $("div.scrollable").scrollable(); $("div.scrollable div.items div img").click(function() { $(this).fadeOut().fadeIn(); var dots = ".."; var fname = $(this).attr("src").match(/[^\.]+/); var src = dots + fname + "Large.jpg"; var caption = "your text here"; switch(fname) { case "personame1": caption = "blurb1"; break; case "personame2": caption= "blurb2"; break; default: caption ="default"; } $(#"caption").html(caption); $("#fullsizepicture img").attr("src",src); $("#block").toggle(); $(".sortPadding").toggle(); $("#caption").html(fname); $("#ImageClose").click(function(){ $("#block").toggle(); $(".sortpadding").toggle(); }); }); });

Aside from that, you can mix vanilla JS with jQuery without any problems (usually).
__________________
The human race is faced with a cruel choice: work or daytime television.

prem ghinde
  Reply With Quote
Old 21-07-2009, 09:45   #3 (permalink)
sarajs
Senior Member
 
sarajs's Avatar
 
Join Date: Jun 2007
Location: London
Posts: 809
Send a message via MSN to sarajs
thank you, I figured it out in the end.

I was trying to pull differenet captions dependant on what image I had showing, and to do that I pulled the name of the image and related it to a case statement.

Thanks for your help
__________________
  Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search


Contact Us - Web Design Forums - Archive
vBulletin © 2000-2009 Jelsoft Enterprises Limited.
Search Engine Optimization by vBSEO 3.0.0 RC8