jQuery – Java2Blog https://java2blog.com A blog on Java, Python and C++ programming languages Sat, 25 Nov 2023 11:40:37 +0000 en-US hourly 1 https://wordpress.org/?v=6.2.9 https://java2blog.com/wp-content/webpc-passthru.php?src=https://java2blog.com/wp-content/uploads/2022/09/cropped-ICON_LOGO_TRANSPARENT-32x32.png&nocache=1 jQuery – Java2Blog https://java2blog.com 32 32 [Solved] uncaught referenceerror: $ is not defined https://java2blog.com/uncaught-referenceerror-is-not-defined-jquery/?utm_source=rss&utm_medium=rss&utm_campaign=uncaught-referenceerror-is-not-defined-jquery https://java2blog.com/uncaught-referenceerror-is-not-defined-jquery/#respond Tue, 08 Oct 2019 09:59:58 +0000 https://java2blog.com/?p=7930 In this post, we will see how to resolve uncaught referenceerror: $ is not defined jquery error.
In jQuery, $ represents jQuery function. You will get this error when you are trying to access anything before loading jQuery.

For example:
request //uncaught referenceerror: $ request is not defined
var request
request // works fine

There can be multiple reasons for this issue.Let’s understand them one by one.


1. You did not add jQuery script

You did not add jQuery script to your PHP/JSP/ASP file correctly. You can use directly link it to jQuery or GoogleCDN or MicrosoftCDN to use jQuery script.

<script src="proxy.php?url=http://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js" type="text/javascript"></script>

You can also download jQuery script and reference it locally for faster performance.


2. You are using jQuery tag before jQuery is loaded.

It could be that you have your script tag called before the jquery script is called.

For example:

<script type="text/javascript" src="proxy.php?url=js/script.js"></script>
<script src="proxy.php?url=http://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js" type="text/javascript"></script>

It will result in $ is not defined.
Change the sequence and it should work fine.

<script src="proxy.php?url=http://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js" type="text/javascript"></script>
<script type="text/javascript" src="proxy.php?url=js/script.js"></script>

So dependent script should be included after jQuery.
Let’s see another example
Let’s say jquery.plugin.js is declared before jquery.min.js, so jquery.plugin uses $, it will complain that $ is not defined which is logical as jQuery was not loaded at correct place.

<script src="proxy.php?url=http://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.plugin.js" type="text/javascript"></script>
<script src="proxy.php?url=http://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js" type="text/javascript"></script>

Change the sequence and it should work fine.

<script src="proxy.php?url=http://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js" type="text/javascript"></script>
<script src="proxy.php?url=http://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.plugin.js" type="text/javascript"></script>

3. Incorrect path/Typo/old jquery location

You might have put an incorrect path, or there may be typo in your file.

For example:
You have misspelt in script as type="text/javacsript". If you notice that here, there is a typo in javascript spelling, and it can cause this issue.

Another reason may be that you are referring to an old jQuery hosted location, which is no longer maintained or moved to a different location.


4. You are offline

This seems bizarre but this may be also the reason for this error.You are working offline but trying to load jQuery from internet.
You can simply download the jQuery.js and use it locally rather then downloading from internet.

<script src="proxy.php?url=/js/jquery.min.js"></script>

That’s all about how to fix uncaught referenceerror: $ is not definedjquery/javascript error.

]]>
https://java2blog.com/uncaught-referenceerror-is-not-defined-jquery/feed/ 0
jQuery html() method example https://java2blog.com/jquery-html-method-example/?utm_source=rss&utm_medium=rss&utm_campaign=jquery-html-method-example https://java2blog.com/jquery-html-method-example/#comments Thu, 08 Sep 2016 05:01:00 +0000 http://www.java2blog.com/?p=121 In this post,  we are going to see jQuery html method.

html method is used to get html content of first matched elements,  other elements will be ignored and html(‘new html content’) is used to set html content for all matched elements.
Syntax for html() :
$("selectors").html() 
Example :
$("div").html();
Syntax for html(‘new html content’) :
$("selectors").html('new html content') 
Example:
 $("div").html('this text is being set by html method');
Let’s understand with the help of example:
Jquery html method example 
  

Jquery html method example


Hello world from java2blog!!!!

Welcome to JQuery.
Live demo:Jquery html method example on jsbin.com ]]>
https://java2blog.com/jquery-html-method-example/feed/ 1
jQuery text() method example https://java2blog.com/jquery-text-method-example/?utm_source=rss&utm_medium=rss&utm_campaign=jquery-text-method-example https://java2blog.com/jquery-text-method-example/#respond Sun, 28 Aug 2016 17:23:00 +0000 http://www.java2blog.com/?p=134 In this post,  we are going to see jQuery text method example.

text method is used to get text of all matched elements and text(‘new text’) is used to set text for all matched elements.
Syntax for text() :
$("selectors").text() 
Example :
$("div").text();
Syntax for text(‘new text’) :
$("selectors").text('new text')
Example:
 $("div").text('this text is being set by text method');
Let’s understand with the help of example:
Jquery text method example 
  

Jquery text method example


Hello world from java2blog!!!!

Welcome to JQuery.
Live demo: Jquery text method example on jsbin.com ]]>
https://java2blog.com/jquery-text-method-example/feed/ 0
jQuery prepend and prependTo example https://java2blog.com/jquery-prepend-and-prependto-example/?utm_source=rss&utm_medium=rss&utm_campaign=jquery-prepend-and-prependto-example https://java2blog.com/jquery-prepend-and-prependto-example/#respond Sat, 27 Aug 2016 17:45:00 +0000 http://www.java2blog.com/?p=135 In this post,  we are going to see jQuery prepend and prependTo methods.

Both do the same task, insert text or html before content of every selected elements, so it will put text or html to first index of selected element. Both methods add text or html as a child to selected elements .Syntax is quite different for for prepend and prepend to nethod.
Syntax for prepend() :
$("selectors").prepend("element to be inserted")
Example :
$("div").prepend("

inserting using prepend

");

Syntax for prependTo() :
$("element to be inserted") .prependTo("div");
Example:
 $("

inserting using prependTo

").prependTo("div");

Let’s understand with the help of example:
Jquery prepend and prependTo example 
  

Jquery prepend and prependTo example

Hello world from java2blog!!!!

Welcome to JQuery.
Live demo: JS Bin on jsbin.com ]]>
https://java2blog.com/jquery-prepend-and-prependto-example/feed/ 0
jQuery before() and insertBefore() example https://java2blog.com/jquery-before-and-insertbefore-example/?utm_source=rss&utm_medium=rss&utm_campaign=jquery-before-and-insertbefore-example https://java2blog.com/jquery-before-and-insertbefore-example/#respond Thu, 25 Aug 2016 17:10:00 +0000 http://www.java2blog.com/?p=139 In this post,  we are going to see jQuery before and insertBefore methods.

Both do the same task, insert text or html before every selected elements but syntax is quite different.

Syntax for after():

$("selectors").before("element to be inserted") ;
Example :
$("div").before("

inserting using after

");

Syntax for insertBefore() :

$("element to be inserted") .insertBefore("div");
Example:
 $("

inserting using insertBefore

").insertBefore("div");

Let’s understand with the help of example:
Jquery before and insertBefore example 
  

Jquery before and insertBefore example

Hello world from java2blog!!!!
Welcome to JQuery.
Live demo: Jquery before and insertBefore example on jsbin.com ]]>
https://java2blog.com/jquery-before-and-insertbefore-example/feed/ 0
jQuery append and append to example https://java2blog.com/jquery-append-and-append-to-example/?utm_source=rss&utm_medium=rss&utm_campaign=jquery-append-and-append-to-example https://java2blog.com/jquery-append-and-append-to-example/#respond Wed, 24 Aug 2016 16:42:00 +0000 http://www.java2blog.com/?p=140 In this post,  we are going to see jQuery append and appendTo methods.

Both do the same task, insert text or html after content of every selected elements, so it will put text or html to last index of selected element. Both methods add text or html as a child to selected elements .Syntax is quite different for append and appendTo methods.
Syntax for append() :
$("selectors").append("element to be inserted")
Example :
$("div").append("

inserting using append

");

Syntax for appendTo() :
$("element to be inserted") .appendTo("div");
Example:
 $("

inserting using appendTo

").appendTo("div");

Let’s understand with the help of example:
Jquery append and appendTo example 
  

Jquery append and appendTo example

Hello world from java2blog!!!!

Welcome to JQuery.
Live demo: Jquery append and appendTo example on jsbin.com ]]>
https://java2blog.com/jquery-append-and-append-to-example/feed/ 0
How to check or uncheck checkbox input or radio button in jQuery https://java2blog.com/check-or-uncheck-checkbox-radio-jquery/?utm_source=rss&utm_medium=rss&utm_campaign=check-or-uncheck-checkbox-radio-jquery https://java2blog.com/check-or-uncheck-checkbox-radio-jquery/#respond Mon, 22 Aug 2016 18:15:00 +0000 http://www.java2blog.com/?p=143
jQuery check/uncheck a check box example
 



jQuery check / uncheck a check box example

Check Me

Live Demo: 

jQuery check/uncheck a check box example on jsbin.com ]]> https://java2blog.com/check-or-uncheck-checkbox-radio-jquery/feed/ 0 How to refresh a page using jQuery https://java2blog.com/how-to-refresh-page-using-jquery/?utm_source=rss&utm_medium=rss&utm_campaign=how-to-refresh-page-using-jquery https://java2blog.com/how-to-refresh-page-using-jquery/#respond Mon, 22 Aug 2016 17:43:00 +0000 http://www.java2blog.com/?p=144 In this post, we will see how to refresh a page using jQuery.
You can use location.reload() method of jQuery to reload the page. It is same as pressing f5 for refreshing a page.

Reload/Refresh a Page in jQuery
    

    


    
Let me know if it works for your browser or not. ]]>
https://java2blog.com/how-to-refresh-page-using-jquery/feed/ 0
jQuery after() and insertAfter() example https://java2blog.com/jquery-after-and-insertafter-example/?utm_source=rss&utm_medium=rss&utm_campaign=jquery-after-and-insertafter-example https://java2blog.com/jquery-after-and-insertafter-example/#respond Mon, 22 Aug 2016 17:32:00 +0000 http://www.java2blog.com/?p=145 In this post,  we are going to see jQuery after and insertAfter methods.

Both do the same task, insert text or html after every selected elements but syntax is quite different.

Syntax for after():

$("selectors").after("element to be inserted") ;
Example :
$("div").after("

inserting using after

");

Syntax for insertAfter() :

$("element to be inserted") .insertAfter("div");
Example:
$("

inserting using insertAfter

").insertAfter("div");

Let’s understand with the help of example:
Jquery after and insertAfter example example 
  

Jquery after and insertAfter example example

Hello world from java2blog!!!!
Welcome to JQuery.
Live demo: Jquery after and insertAfter example example on jsbin.com ]]>
https://java2blog.com/jquery-after-and-insertafter-example/feed/ 0