Skip to main content

This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.

Themes

Discuss SilverStripe Themes.

Moderators: martimiz, Sean, biapar, Willr, Ingo, swaiba, simon_w

$SilverStripeNavigator breaks my jQuery script


Reply

5 Posts   927 Views

Avatar
anebg

23 November 2010 at 4:52am Community Member, 8 Posts

How do I tell my jquery script to use something else than $ ?

Do I have to change all the $ to _$ ?

This is my script

$(document).ready(function() {
$('.slideshow').cycle({
      fx: 'fade',
      timeout: 6000
   });
});

Avatar
Invader_Zim

23 November 2010 at 5:00am Community Member, 141 Posts

Hi,

try this in your script:

(function($) {
   
$(document).ready(function(){
      // your jquery awesomeness.
})

})(jQuery);

more info here: [url]http://doc.silverstripe.org/javascript[/url]

Cheers,
Christian

Avatar
anebg

23 November 2010 at 5:12am Community Member, 8 Posts

Works like a charm. Thank you!

Avatar
biapar

12 December 2010 at 9:28pm Forum Moderator, 435 Posts

Or use JQuery.NoConflict

Avatar
bennettpr

15 December 2010 at 11:36am Community Member, 37 Posts

To expand on biapar's reply, something like this will stop your custom scripts from interfering with other scripts already using the $ namespace / function:

$.noConflict();

jQuery(document).ready(function() {
jQuery('#myid').click(....)
});