[Special Summer Sale] 40% OFF All Magento 2 Themes

Cart

JQuery – $ is not defined

  • This topic is empty.
Viewing 15 posts - 1 through 15 (of 31 total)
  • Author
    Posts
  • #9710
    paul-creasey
    Participant

    I have a simple jquery click event

    <script type="text/javascript">
        $(function() {
            $('#post').click(function() {
                alert("test"); 
            });
        });
    </script>
    

    and a jquery reference defined in the site.master

    <script src="<%=ResolveUrl("~/Scripts/jquery-1.3.2.js")%>" type="text/javascript"></script>
    

    I have checked that the script is being resolved correctly, I’m able to see the markup and view the script directly in firebug, so I must be being found. However, I am still getting:

    $ is not defined

    and none of the jquery works. I’ve also tried the various variations of this like $(document).ready and jQuery etc.

    It’s an MVC 2 app on .net 3.5, I’m sure I’m being really dense, everywhere on google says to check the file is referenced correctly, which I have checked and checked again, please advise! :/

    #9738
    tambler
    Participant

    Are you using any other JavaScript libraries? If so, you will probably need to use jQuery in compatibility mode:

    http://docs.jquery.com/Using_jQuery_with_Other_Libraries

    #9731
    mdm20
    Participant

    I use Url.Content and never have a problem.

    <script src="<%= Url.Content ("~/Scripts/jquery-1.4.1.min.js") %>" type="text/javascript"></script>
    
    #9734
    alan
    Participant

    I got the same error message when I misspelled the jQuery reference and instead of type="text/javascript" I typed “…javascirpt”. 😉

    #9725
    cedd
    Participant

    I had this problem once for no apparent reason. It was happenning locally whilst I was running through the aspnet development server. It had been working and I reverted everything to a state where it had previously been working and still it didn’t work. I looked in the chrome debugger and the jquery-1.7.1.min.js had loaded without any problems. It was all very confusing. I still don’t know what the problem was but closing the browser, closing the development server and then trying again sorted it out.

    #9712
    roys_philippines
    Participant

    We have the same problem….but accidentally i checked folder properties and set something…

    You have to check the properties of each folders that you’re accessing..

    1. right click folder
    2. ‘permissions’ tab
    3. set the folder access :
      OWNER: create and delete files
      GROUP: access files
      OTHERS: access files

    I hope that this is the solution……

    #9732
    user1284907
    Participant

    In the solution it is mentioned –
    “One final thing to check is to make sure that you are not loading any plugins before you load jQuery. Plugins extend the “$” object, so if you load a plugin before loading jQuery core, then you’ll get the error you described.”

    For avoiding this –

    Many JavaScript libraries use $ as a function or variable name, just as jQuery does. In jQuery’s case, $ is just an alias for jQuery, so all functionality is available without using $. If we need to use another JavaScript library alongside jQuery, we can return control of $ back to the other library with a call to $.noConflict():

    #9726
    vikrantx
    Participant

    Just place jquery url on the top of your jquery code

    like this–

    <script src="<%=ResolveUrl("~/Scripts/jquery-1.3.2.js")%>" type="text/javascript"></script>
    
    <script type="text/javascript">
        $(function() {
            $('#post').click(function() {
                alert("test"); 
            });
        });
    </script>
    
    #9735
    alexender-dumma
    Participant

    It sounds like jQuery isn’t loading properly. Which source/version are you using?

    Alternatively, it could a be namespace collision, so try using jQuery explicitly instead of using $. If that works, you may like to use noConflict to ensure the other code that’s using $ doesn’t break.

    #9727
    anthony
    Participant

    I had the same problem and it was because my reference to the jQuery.js was not in the tag. Once I switched that, everything started working.

    Anthony

    #9713
    francis-musignac
    Participant

    When using jQuery in asp.net, if you are using a master page and you are loading the jquery source file there, make sure you have the header contentplaceholder after all the jquery script references.

    I had a problem where any pages that used that master page would return ‘$ is not defined’ simply because the incorrect order was making the client side code run before the jquery object was created. So make sure you have:

    <head runat="server">
        <script type="text/javascript" src="Scripts/jquery-VERSION#.js"></script>
        <asp:ContentPlaceHolder id="Header" runat="server"></asp:ContentPlaceHolder>
    </head>
    

    That way the code will run in order and you will be able to run jQuery code on the child pages.

    #9714
    anthony
    Participant

    In my case I was pointing to Google hosted JQuery. It was included properly, but I was on an HTTPS page and calling it via HTTP. Once I fixed the problem (or allowed insecure content), it fired right up.

    #9715
    spring
    Participant

    After tried everything here with no result, I solved the problem simply by moving the script src tag from body to head

    #9737
    mimouni
    Participant

    after some tests i found a fast solution ,
    you can add in top of your index page:

    <script>
    $=jQuery;
    </script>
    

    it work very fine 🙂

    #9716
    gavin
    Participant

    I was having this same problem and couldn’t figure out what was causing it. I recently converted my HTML files from Japanese to UTF-8, but I didn’t do anything with the script files. Somehow jquery-1.10.2.min.js became corrupted in this process (I still have no idea how). Replacing jquery-1.10.2.min.js with the original fixed it.

Viewing 15 posts - 1 through 15 (of 31 total)
  • You must be logged in to reply to this topic.