0

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

1
  • Uh, you're missing a });... Commented Aug 9, 2010 at 3:46

3 Answers 3

3

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

Sign up to request clarification or add additional context in comments.

1 Comment

WordPress automatically puts jQuery into compatibility mode, so you definitely need to use jQuery instead of $ outside of the function.
1

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.

Comments

0

2 Comments

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.