[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

How to write a proper ELSE statement

Posted on 2011-10-13
4
Medium Priority
?
138 Views
Last Modified: 2012-05-12
Hi all. I have currently am using this javascript:

<script language="javascript">
$(document).ready(function(){
                  $("a[rel^='prettyPhoto']").prettyPhoto({
                  theme:'pp_default',
                  showTitle: true
                  });

            });
</script>

What I want to add is that IF rel=prettyPhoto2 THEN theme:'new_theme'

Not sure how to properly do this.
0
Comment
Question by:tekgrl
  • 2
4 Comments
 
LVL 12

Accepted Solution

by:
zappafan2k2 earned 2000 total points
ID: 36962509
Since you're using jQuery, you could accomplish this like:
$(document).ready(function(){
              $("a[rel=prettyPhoto2]").prettyPhoto({           // this will only match prettyPhoto2
                  theme:'new_theme',
                  showTitle: true
                  });

              $("a[rel^='prettyPhoto']").not("a[rel=prettyPhoto2]").prettyPhoto({    // this will match all others
                  theme:'pp_default',
                  showTitle: true
                  });

            });

Open in new window

What do you think?
0
 
LVL 3

Expert Comment

by:Piotr D
ID: 36962550
Assuming you use jQuery here, the best to achieve your goal would be iterating an array with each(), like this:
$.each($("a[rel^=prettyPhoto]"), 
  function(itemIndex, item) {
   item.prettyPhoto({
     theme: (item.attr("rel")=='prettyPhoto2')? 'new_theme' : 'pp_default',
     showTitle: true
   });
  }
);

Open in new window

0
 
LVL 3

Expert Comment

by:Piotr D
ID: 36962569
Oops, sorry, small glitch. Use this instead:
$.each($("a[rel^=prettyPhoto]"), 
  function(itemIndex, item) {
   item.prettyPhoto({
     theme: (item.rel=='prettyPhoto2')? 'new_theme' : 'pp_default',
     showTitle: true
   });
  }
);

Open in new window

0
 

Author Closing Comment

by:tekgrl
ID: 36962711
Beautiful! Thanks.
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Article by: DanRollins
This article describes a JavaScript program that creates a maze made of hexagonal cells.  In Part 2 (http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/A_7850-Hex-Maze-Part-2.html), we'll extend the program by adding a depth-…
This article will give core knowledge of JavaScript and will head in to your first JavaScript program. I am Durvesh Naik and I am here to deal with this series of JavaScript. I will teach you JavaScript in part wise , as its quite boring to read big…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…
Suggested Courses

834 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question