WordPress.org

Ready to get started?Download WordPress

Forums

Why jQuery doesn't work as it should? (6 posts)

  1. s0what
    Member
    Posted 3 years ago #

    Hi!

    I have some custom jQuery functions in my blog, to run them, I need to include standard jQuery library. Why the library, which comes with WordPress doesn't run these standard functions?

    here are some examples of my functions:

    <script type="text/javascript">
    $(function(){
    	$('#show').click(function() {
    	  $('#sidebar').slideToggle('slow');
    	  $('#top').slideToggle('slow');
    	  $("#front-list").animate({ width:"590px" }, 1500 );
    	  $("#content").animate({ width:"590px" }, 1500 );
    	  $('#show').hide();
    	  $('#hide').show();
    	});
    
    	$('#nav_rakstu').mouseover(function(){
    	 $('.post-ratings').append("<span class='post-ratings-text'><br />Blaa blaa</span>");
    	});
    	$('#nav_rakstu').mouseout(function(){
    	 $('.post-ratings-text').remove();
    	});
    });
    </script>
  2. esmi
    Theme Diva & Forum Moderator
    Posted 3 years ago #

  3. s0what
    Member
    Posted 3 years ago #

    thanks, esmi! You helped me again :)

    But I don't understand how my code has to be modified. Can you please help me?

  4. Darrell Schauss
    Member
    Posted 3 years ago #

    Try like this. Reduce conflict and runs the jquery only after the page is finished and the elements exist to be manipulated.

    <script type="text/javascript">
    
         var $j = jQuery.noConflict();
    
         // Use jQuery via $j(...) instead of $(..)
         $j(document).ready(function(){
    
           $j('#show').click(function() {
           .....
           }
    
         });
       </script>
  5. esmi
    Theme Diva & Forum Moderator
    Posted 3 years ago #

    As darrellonsite said, you need to look at jQuery noConflict wrappers. The explanation and workaround are near the bottom of the wp_enqueue_script Codex page.

  6. s0what
    Member
    Posted 3 years ago #

    thanks again!

    I found a solution myself :)
    I just had to replace $ with jQuery and put <?php wp_head(); ?> before script.

    Is there any reason now to run script the way darrellonsite said?

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags