typo_
typo_

Reputation: 21

How to properly use jQuery noConflict mode in Wordpress

I have the following functional (in html) jsfiddle: http://jsfiddle.net/pmpvLjuq/1/

I've found that in order to be functional in Wordpress too, should be used in jQuery's noConflict mode. In wp codex I've found this section:

At this point, I'm not so sure if I understand the global term in these circumstances. Should I replace all the $ signs with jQuery ?

What I've done without error in the console (but I'm concerned) also working in wp pages it's here: http://jsfiddle.net/8r9rcft2/2/

In other words, in these particular cases should I still replace the $ mark(?)

line 15 $links = $(".pagedMenu li"), will be jQuerylinks = jQuery(".pagedMenu li"),(?)

line 16 count = $links.length, will be count = jQuerylinks.length, (?) line

The same for lines 25,26,26, ect.

Can I have your prepared for wordpress jsfiddle in jQuery's noConflict mode in order to have the whole picture of this process please?

Can you please confirm, as a rule of thumb, if I dont receive any error in the browser console that means everything is fine in the code? Thanks

Upvotes: 1

Views: 1860

Answers (2)

Yatin Khullar
Yatin Khullar

Reputation: 1590

I always prefer below method because it always separate jquery libraries and never conflict and it is one of recommended method of jquery.

Its just a example. I mostly used it for smooth scrooling.

$scroll= jQuery.noConflict();    
$scroll('a').click(function(){
    $scroll('html, body').animate({
        scrollTop: $scroll( $scroll(this).attr('href') ).offset().top
    }, 1000);
    return false;
});

Upvotes: 2

Renish Khunt
Renish Khunt

Reputation: 5824

I always used jQuery like this in wordpress and it's working for me I hop this is working for you.

(function($){

  $(document).ready(function(){
      // write code here
  });

  // or also you can write jquery code like this

  jQuery(document).ready(function(){
      // write code here
  });

})(jQuery);

Upvotes: 3

Related Questions