Forums

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

Home Forums CSS [Solved] simple jQuery not working in wordpress

  • This topic is empty.
Viewing 5 posts - 1 through 5 (of 5 total)
  • Author
    Posts
  • #23106
    rayishu
    Member

    I have a page in wordpress, im putting all my html in that page using the wordpress editor
    i have included my own JS in the header

    NONE OF MY JQUERY SCRIPTS WORK IN WORDPRESS I DONT KNOW WHY

    here is the page http://khaledstudios.com/?page_id=11

    all there is, is a link there that says click me

    and here is the JS

    Code:
    $(document).ready(function() {
    $(‘a’).click(functino(event) {
    $(this).preventDefault();
    alert(‘abc’);
    });
    });

    this sould work i dont know why it isnt.

    #49331
    rayishu
    Member

    srry i fixed that, i wrote that script just for a quick demonstration purpose. i fixed the problem and i still get the problem. ….

    #49286
    rayishu
    Member

    ok i figured it out. in wordpress instead of using $() notation you have to use jQuery();
    thx for your guys help

    #70909
    Steven Gardner
    Participant

    I am having similar problems. I am trying to create a simple jquery accordion effect for a gym class timetable.
    I have added

    Code:

    To the Header.php
    and linked to my script just under

    Code:

    with

    Code:

    Like Chris mentions in his WordPress book!

    Here is the jquery file

    Code:
    function initMenus() {
    $(‘ul.menu ul’).hide();
    $.each($(‘ul.menu’), function(){
    $(‘#’ + this.id + ‘.expandfirst ul:first’).show();
    });
    $(‘ul.menu li a’).click(
    function() {
    var checkElement = $(this).next();
    var parent = this.parentNode.parentNode.id;

    if($(‘#’ + parent).hasClass(‘noaccordion’)) {
    $(this).next().slideToggle(‘normal’);
    return false;
    }
    if((checkElement.is(‘ul’)) && (checkElement.is(‘:visible’))) {
    if($(‘#’ + parent).hasClass(‘collapsible’)) {
    $(‘#’ + parent + ‘ ul:visible’).slideUp(‘normal’);
    }
    return false;
    }
    if((checkElement.is(‘ul’)) && (!checkElement.is(‘:visible’))) {
    $(‘#’ + parent + ‘ ul:visible’).slideUp(‘normal’);
    checkElement.slideDown(‘normal’);
    return false;
    }
    }
    );
    }
    $(document).ready(function() {initMenus();});

    yet when i addd the html code in the page when i preview it there is no jquery in motion.

    Does anyone have an idea of where i am going wrong?
    This is my first attempt at adding jquery in wordpress without using a wordpress plugin.
    Just noticed this thread is in the CSS Section. Not sure why!

    #70944
    Steven Gardner
    Participant

    Found out else where that i need to replace

    Code:
    $

    with

    Code:
    jQuery

    for this script to work in wordpress.

    Thanks

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