Forums

The forums ran from 2008-2020 and are now closed and viewable here as an archive.

Home Forums JavaScript jQuery not responding once I move it to wordpress

  • This topic is empty.
Viewing 12 posts - 1 through 12 (of 12 total)
  • Author
    Posts
  • #31355
    #64399
    Rob MacKay
    Participant

    Hey. Yea. It’s the way WordPress loads scripts to remove the problem of duplication and clashes between libraries.

    have a look here:

    http://codex.wordpress.org/Function_Reference/wp_enqueue_script

    or just wrap your jQuery in this document ready, instead of the default:

    jQuery(document).ready(function($) {

    #64392

    Are you saying jQuery is not working? It is, I tested it.

    So I changed…

    $(function() {	

    with

    jQuery(document).ready(function($) {

    but still not working.

    #64375
    Rob MacKay
    Participant

    Yes.

    If you have a read through the page I linked it might make a little more sense too :)

    and here too:

    http://digwp.com/2009/06/including-jquery-in-wordpress-the-right-way/

    #64302

    Ok, it’s finally responding. But jQuery is not adding to the #mover.

    This is some craziness!

    #64149

    I tried that. Not working.

    The jQuert is adding the distance to the list items, just not the #mover.

    #64119
    clokey2k
    Participant

    I have been staring at this one for some time now. Checking the script from ‘DOM ready’, comparing the scripts (and CSS :-) ). But now I have found it!!!

    HTML 5 data- Attributes

    As of jQuery 1.4.3 HTML 5 data- attributes will be automatically pulled in to jQuery’s data object.

    You are including 1.4.2, so the ‘data-pos’ HTML attribute is ignored. So, either include a newer version of jquery or change:

    jQuery("#mover").css("left", -($el.data("pos") * speed - 40));

    to:

    jQuery("#mover").css("left", -($el.attr("data-pos") * speed - 40));

    BTW You can use ‘$’ to reference jquery while inside the :

    jQuery(document).ready(function($) {
    }

    I also don’t think you need to use the no-conflict mode of jquery. If you are still loading the script via the deregister/register scripting in the ‘function.php’, as it unloads WordPress’s warped version of jQuery (but leaves the original jQuery for admin pages!).

    I could be wrong, on all accounts – but I have learnt a few things while playing :-p

    #64071
    noahgelman
    Participant

    Yeah, I had the same issue with this not working (although not on wordpress), you have to update to 1.4.3 in order for it to work

    #64072

    Yes! Thanks Clokey! Good things will happen to you this week.

    I wonder why the following code pulls an older JQ library? Seems like it would pull the newest.

    #64073
    noahgelman
    Participant

    I believe that links locally, you probably can just rip out that line and link straight to googles newest version and be fine. You should do that anyway.

    #64081
    Rob MacKay
    Participant

    It just links locally by default because WP comes “supplied” with a copy of jQuery.

    http://codex.wordpress.org/Function_Reference/wp_enqueue_script#Example

    Shows how to pull it from the CDN :)

    #80522
    clokey2k
    Participant

    I posted this in response to someone else recently (I thought it was you @aaronheine), and I referred to it earlier but didn’t link it: https://css-tricks.com/forums/discussion/comment/40341/#Comment_40341

    I use this script, it includes the deregistering of WP’s jQuery, pulling in the Google CDN version, and loading other plugins etc. The plugins loading based on dependancy aswell;

Viewing 12 posts - 1 through 12 (of 12 total)
  • The forum ‘JavaScript’ is closed to new topics and replies.