Support » Plugins and Hacks » Hacks » Error implementing JQuery

  • Hi!

    I am trying to implement a jquery code onto my website. The code I am using is based on http://jsfiddle.net/karalamalar/grnQA/

    This is what I have done:

    A. Created a Folder called JS in my theme. Inside I created a file called share.js and inserted the following code:

    [ Code edited with backticks. Moderator note: when sharing code examples, please wrap the code in backticks or use the code button. ]

    jQuery(document).ready(function($) {
    function fixDiv() {
    var $cache = $('#getFixed');
    if ($(window).scrollTop() > 100)
    $cache.css({'position': 'fixed', 'top': '10px'});
    else
    $cache.css({'position': 'relative', 'top': 'auto'});
    }
    $(window).scroll(fixDiv);
    fixDiv();
    });

    B. I edited the functions.php file by adding the following code:

    function insert_jquery() {
    wp_enqueue_script(
    'share', // name your script so that you can attach other scripts and de-register, etc.
    get_template_directory_uri() . '/js/share.js', // this is the location of your script file
    array('jquery') // this array lists the scripts upon which your script depends
    );
    }
    
    add_filter('wp_head','insert_jquery');

    C. I edited the CSS by adding the following code:

    #getFixed { color: #c00; font: bold 15px arial; padding: 10px; margin: 10px; border: 1px solid #c00; width: 200px; }

    D. I edited the single post file with the following code:

    <div id="getFixed">This div is going to be fixed</div>

    What I get: http://beta.projectcloud.info/nirma-university-law-journal-volume-ii-issue-ii/

    I can view the the message but the jquery is not working. Ideally it would stay at the top of the screen. Any inputs?

  • The topic ‘Error implementing JQuery’ is closed to new replies.