Support » Plugins » Hacks » Error implementing JQuery

  • Hi!

    I am trying to implement a jquery code onto my website. The code I am using is based on

    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'});
    $cache.css({'position': 'relative', 'top': 'auto'});

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

    function insert_jquery() {
    '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

    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:

    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.