Link to home
Start Free TrialLog in
Avatar of tekgrl
tekgrl

asked on

How to write a proper ELSE statement

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.
ASKER CERTIFIED SOLUTION
Avatar of zappafan2k2
zappafan2k2

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
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

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

Avatar of tekgrl
tekgrl

ASKER

Beautiful! Thanks.