javascript - If body class equals X then do something? -


i have code running external script image slider every page on site.

$(document).ready(function() {   $("#slideshow").show();   $('#slider1').anythingslider({     buildnavigation: false,     delay: 8000     }) 

on 1 of pages don't want image slider rotate automatically need add variable. i've put class on body of page , want along lines of...

if body has class of 'partnercharitiesdetail' run script instead of generic one

this have tried below (without success). have 2 questions really,

1) happens in jquery when there 2 identical scripts running (like example), overwrite older 1 newer one?

2) going wrong?! approach best way it?

$(document).ready(function() {  $("#slideshow").show();   $('#slider1').anythingslider({     buildnavigation: false,     delay: 8000   })    if ($('body.partnercharitiesdetail').length > 0){   $('#slider1').anythingslider({   buildnavigation: false,   delay: 8000,   startstopped: false  })  } 

thanks!

use hasclass() method check if element has class.

also, code little repetitive (and cause anythingslider run twice) — write instead:

$(document).ready(function() {     // initialize options first     var options = {         buildnavigation: false,          delay: 8000     };      // disable startstopped if body has class     if ($('body').hasclass('partnercharitiesdetail')) {         options.startstopped = false;     }      // show #slideshow element , start slideshow     $('#slideshow').show();     $('#slider1').anythingslider(options); }); 

Comments

Popular posts from this blog

asp.net - repeatedly call AddImageUrl(url) to assemble pdf document -

java - Android recognize cell phone with keyboard or not? -

iphone - How would you achieve a LED Scrolling effect? -