treehouse : what would you like to learn today?
Web Design Web Development iOS Development

[Solved] simple jQuery not working in wordpress

  • 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

    $(document).ready(function() {
    $('a').click(functino(event) {
    $(this).preventDefault();
    alert('abc');
    });
    });


    this sould work i dont know why it isnt.
  • well right off the bat i can see that you spelled function wrong

    you have this
    $('a').click(functino(event) {

    i am sure it's suppose to be this
    $('a').click(function(event) {
  • srry i fixed that, i wrote that script just for a quick demonstration purpose. i fixed the problem and i still get the problem. ....
  • have you included the jquery library into your head section?
  • try doing this.

    1. Include the jquery library into the head section of your code

    <script type="text/javascript" src="jquery-1.2.6.min.js"></script> //Make sure to download this version from the jquery site.

    2. Change you code to this

    <script type="text/javascript">

    $(function(){
    $("a").click(function(){
    alert("abc");
    });
    });
    </script>

    Notice the change from single quotes to double
  • ok i figured it out. in wordpress instead of using $() notation you have to use jQuery();
    thx for your guys help
  • I am having similar problems. I am trying to create a simple jquery accordion effect for a gym class timetable.
    I have added
    <?php wp_enqueue_script(\"jquery\"); ?>

    <?php wp_head(); ?>
    To the Header.php
    and linked to my script just under
    <?php wp_head(); ?>
    with
    <script type=\"text/javascript\" src=\"<?php bloginfo(\"template_url\"); ?>/style/scripts/menu.js\"></script>
    Like Chris mentions in his Wordpress book!

    Here is the jquery file
    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!
  • Found out else where that i need to replace
    $
    with
    jQuery
    for this script to work in wordpress.

    Thanks