Ask your WordPress questions! Pay money and get answers fast! Comodo Trusted Site Seal
Official PayPal Seal

Add jquery function initialization in the header WordPress

I have to add this code in the header to make anythingslider work:
<script>// DOM Ready
$(function(){$('#slider').anythingSlider();});</script>


After some trials i've discoverd that anythingslider does not slide because no initialization take place. How can i make it work?

It's urgent.

Thanks

Answers (3)

2012-08-12

Baki Goxhaj answers:

Use this:

<script>
jQuery(document).ready(function($) {
$('#slider').anythingSlider();
});
</script>


You need to run that peace of code after the DOM has been loaded, that is.


maryhellen comments:

does not work, looka t the result:
http://www.progettobenesserecompleto.it/nonabusaredegliunderscore/

no slideshow only static slides


maryhellen comments:

Resolved thanks, i removed another initialization script before this one and now everything works fine.

Thanks a lot


Baki Goxhaj comments:

Cool! It made no sense not to work :)


maryhellen comments:

Hi, i had to added another initialization script just before anythingslider:
now i have this:

<script type="text/javascript">
jQuery(document).ready(function($) {$('#cont-tab').organicTabs();});</script>
<!-- AnythingSlider initialization -->
<script type="text/javascript">
jQuery(document).ready(function($) {
$('#slider').anythingSlider();

});

and neither of two work.
Original organic tab script initialization was:

<script>$(function() {$("#cont-tab").organicTabs();});</script>
Thanks for your help


Baki Goxhaj comments:

Try this:

<script type="text/javascript">
jQuery(document).ready(function($) {

$('#cont-tab').organicTabs();
$('#slider').anythingSlider();

});
</script>


maryhellen comments:

It does not work.


Baki Goxhaj comments:

You're organicTabs source link is not right:

http://www.progettobenesserecompleto.it/nonabusaredegliunderscore/wp-content/themes/twentyeleven/js/organictabs.jquery.js

Check you have the file in the /js/ folder.


maryhellen comments:

Thanks, you are right. Now everything work fine.

Thanks again


maryhellen comments:

Can you explaim please why insert direct initialization function does not work?

Thanks


Baki Goxhaj comments:

Did not get it very much. Can you please explain further and provide the code you are using to achieve what you need.


maryhellen comments:

Sorry, my does not help to communicate clearly: your script work fine, i'd like to know why this kind of code:
<script>// DOM Ready

$(function(){$('#slider').anythingSlider();});</script>


does not work in wordpress.

Thanks


Baki Goxhaj comments:

This would work if you put that in the footer because it assumes the DOM has been loaded and runs automatically. Bun the the case of WordPress there is one extra condition. That would work if it is in the footer and you are using and external CDN for jQuery. If you enqueue the jQuery files that comes with WordPress, you will have to run jQuery code in no-conflict mode as I told you above, because the dolar sign ($) in that case is reserved for all scripts that come with WordPress. Makes sense?


maryhellen comments:

Yes, maje sense. Thanks for yoi patience.

Have nice day, wherever you are.

2012-08-16

Giulio Mainardi answers:

Hi all, this is possible too(http://api.jquery.com/jQuery/#jQuery3):

jQuery(function($) {
$('#slider').anythingSlider();
});

2012-08-17

Hardeep Singh answers:

Use this instead:

<script>

// DOM Ready
jQuery(document).ready(function($) {
jQuery('#slider').anythingSlider();
});

</script>

This is not same as other responses and can be used in header too.

Thanks