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

Viewing 2 replies - 1 through 2 (of 2 total)
  • Moderator Jose Castaneda

    (@jcastaneda)

    THEME COFFEE MONKEY

    The main reason it may not work is because the post editor will strip out any script elements. It is for security reasons. There are plugins that may allow you to add that capability.

    Thread Starter aemolinas

    (@aemolinas)

    Thanks for the response Jose Castaneda.
    I tried using this plugin, and pasting my code in the window it provided, but that didn’t work either. I’m still somewhat new at working with both jQuery and wordpress. Could you, or someone, point me to a better plugin perhaps, or good clear instructions on the correct way to include my script as a separate file?

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘jquery not working in post’ is closed to new replies.