user397466
user397466

Reputation: 41

jQuery in Wordpress

I am using WP3 and am using some simple JQ to style some elements.

However, I cannot get it to work.

I am aware of but beyond that I don't know where to put my own code exactly, in which file or place. The code is:

<script>
$(document).ready(function(){
 $("#image" + photoNum).animate({ opacity: 0, scale: 3 }, 0);
</script>

Which works outside of WP, but not in it.

Any ideas?

Thank you

Upvotes: 0

Views: 287

Answers (3)

Anraiki
Anraiki

Reputation: 796

For some reason the $ needs to be reassign in Wordpress or it will not work at all. I am not too familiar with how Wordpress and Jquery works, but I recall getting this snippet and having everything work properly.

$j=jQuery.noConflict();

Your coding would be as follow... which should also be closed with }); as some of the people on SO have answered.

<script>
$j(document).ready(function(){
 $j("#image" + photoNum).animate({ opacity: 0, scale: 3 }, 0);
});
</script>

Also in Ben's code, you can see there are no symbols to call jquery but the word itself.

Upvotes: 1

Ben Kulbertis
Ben Kulbertis

Reputation: 1713

One of the biggest problems is that you are not ending the function, you need to add }); to the end. If that does not fix it, something that I discovered is that there are often issues with plugins using other frameworks, so for the $(document).ready() wrap, use "jQuery" instead of "$" like so:

<script>
jQuery(document).ready(function(){
 $("#image" + photoNum).animate({ opacity: 0, scale: 3 }, 0);
});
</script>

You can however, continue to use "$" within the function. But any unwrapped code probably needs to use "jQuery".

Upvotes: 3

JohnB
JohnB

Reputation: 18972

Upvotes: 0

Related Questions