-1

I got my jQuery working fine in jsfiddle. However, it won't work in my actual application because of the dom.

I'm new at this, i think I might be using the wrong syntax or something?

Here's my jsfiddle, note that it works if you select domready but not wrap.. I'm really confused

Here's the actual code:

$curr = $('#first');

$(document).ready(function () {
   $('.next').click(function () {
    $curr.hide();
    $curr = $curr.next();
    $curr.show();
});
});

$(document).ready(function () {
$('.previous').click(function () {
    $curr.hide();
    $curr = $curr.prev();
    $curr.show();
  });
});
1
  • Your code has to either be in a "load" or "ready" handler, or "no wrap" at the end of the <body>. Commented Apr 8, 2014 at 18:57

2 Answers 2

0

Try this:

$(document).ready(function () {
   $curr = $('#first');

   $('.next').click(function () {
      $curr.hide();
      $curr = $curr.next();
      $curr.show();
   });

   $('.previous').click(function () {
      $curr.hide();
      $curr = $curr.prev();
     $curr.show();

   });
});

No need for multiple document.ready events in your case :)

Sign up to request clarification or add additional context in comments.

2 Comments

Thanks for the tip :) makes sense. Works perfectly in jsfiddle, in my application I get an "Uncaught ReferenceError: $ is not defined " though.. any ideas?
Yes, that means that the jquery library has not been included in your page. w3schools.com/jquery/jquery_install.asp....Either download it from the CDN, else download it store it locally on your PC an give the relative path..hope it helps
0

Try using this code instead:

jQuery(document).ready(function ($) {
    $curr = $('#first');

    $('.next').click(function () {
        $curr.hide();
        $curr = $curr.next();
        $curr.show();
    });

    $('.previous').click(function () {
        $curr.hide();
        $curr = $curr.prev();
        $curr.show();   
    });
});

1 Comment

Thank you, this works in jsfiddle. When I put it on my actual application I get "Uncaught ReferenceError: $ is not defined " "anonymous function" error though.. pointing to this JS. Any ideas? There are no typo

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.