jquery not working in post
-
How can I get the following jquery script working in a post?
<script src="/wp-includes/js/jquery/jquery.js" type="text/javascript">// <![CDATA[ (function($) { var curPH = 1; $(document).ready(function(){ reStyle(); $('#phs').css('visibility','visible'); }); $('#linkZ > a').live('click', function(){ curPH = $(this).text(); reStyle(); }); function reStyle(){ for(var i=0; $('#linkZ > a').length > i;i++){ if(curPH == $('#linkZ > a:eq('+i+')').text()){ $('#linkZ > a:eq('+i+')').css('text-decoration', 'underline'); $('#phs > div:eq('+i+')').fadeIn('normal'); }else{ $('#linkZ > a:eq('+i+')').css('text-decoration', 'none'); $('#phs > div:eq('+i+')').hide(); } } } })(jQuery); // ]]></script>
I have read as much as I could on this forum and other places, and I gather that jQuery is implemented with WordPress by default. I have also checked to see that it is being enqueued in the header of my theme with this line of code:
<?php wp_enqueue_script('jquery'); ?>
I have also tried to wrap the script so that it will be read in no conflicts mode as has been mentioned in this forum.
I am pasting the above code directly into a post. I turned off the editor to ensure that it was not altering my code when I created the post.
I tested the code on the website jquery fiddles, and it functioned there. It also worked on a old joomla sight, so I’m confident the code is valid.
I guess I must be doing something wrong accessing jquery on the site.
I have also tried installing a plugin to use the google hosted jquery library, but didn’t help either.
Can anyone point me to where I have gone wrong. I’ve been at this a couple of days.
- The topic ‘jquery not working in post’ is closed to new replies.