views:

52

answers:

3

Hello.

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

A: 
JohnB
Ive seen that, I said I'm aware of it, but if it's not blatantly showing me how to apply my code then I'm not sure where it goes.
**1.** Where do you want to put it, i.e. all the posts? **2.** Have you linked to all the .js files that you need on the page that you want it? I assume you know how to link to a .js file, because you said you got it working outside of Wordpress.
JohnB
+2  A: 

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".

Ben
WordPress automatically puts jQuery into compatibility mode, so you definitely need to use jQuery instead of $ outside of the function.
John P Bloch
A: 

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.

Anraiki