help in jquery basic code

Discussion in 'jQuery' started by rohit0714, Jul 28, 2011.

  1. #1
    $ is not defined
    [Break On This Error] $(document).ready(function() {

    this error in this code



    //jquery//
    2
    3$(document).ready(function() {
    4 $(".image").click(function(){
    5 $(".jq").show();
    6 });
    7 $("button").click(function(){
    8 $(".jq").hide();
    9 });
    10
    11
    12
    13});



    in index file i have used <script type="text/javascript" src="jq.js"></script>

    please help
     
    rohit0714, Jul 28, 2011 IP
  2. Perpetual infinity

    Perpetual infinity Peon

    Messages:
    8
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #2
    is the jq.js file in the header?
    is it in the same directory as the file with the above code in?
    Try wrapping the jQ in
    (function( $ ){
    
    //code here
    
    })( jQuery );
    Code (markup):
     
    Perpetual infinity, Jul 29, 2011 IP
  3. traihu

    traihu Peon

    Messages:
    3
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Replace code : <script type="text/javascript" src="jq.js"></script>

    <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.4.4/jquery.min.js"></script>

    :):)
     
    traihu, Aug 3, 2011 IP
  4. freelancewebaz

    freelancewebaz Well-Known Member

    Messages:
    976
    Likes Received:
    23
    Best Answers:
    1
    Trophy Points:
    145
    #4
    Why would you tell him to use an old version?  Use the current version man.

    <script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.6.2/jquery.min.js" />
     
    freelancewebaz, Aug 4, 2011 IP
  5. xemsol

    xemsol Peon

    Messages:
    10
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #5
    you got the error because you didnt included the jQuery library on your page. So include the jQuery library using
    as freelancewebas mentioned. And hopefully you will be able to get rid of error.
     
    xemsol, Aug 23, 2011 IP
  6. astoever

    astoever Peon

    Messages:
    65
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #6
    Well, while we're on the subject. CDN with fallback and protocol relative URL:

    <script src="//ajax.googleapis.com/ajax/libs/jquery/1.6.2/jquery.min.js"></script>
    <script>window.jQuery || document.write('<script src="/path/to/fallback/jquery-1.6.2.min.js"><\/script>')</script>
     
    astoever, Sep 6, 2011 IP