jQuery is a fast, small, and feature-rich JavaScript library. It makes things like HTML document traversal and manipulation, event handling, animation, and Ajax much simpler with an easy-to-use API that works across a multitude of browsers. With a combination of versatility and extensibility, jQuery has changed the way that millions of people write JavaScript. |
Example 1) Hide all the content in <p> tag based in jQuery.
<!DOCTYPE html> <html> <head> <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script> <script> $(document).ready(function(){ $("p").click(function(){ $(this).hide(); }); }); </script> </head> <body> <p>If you click on me, I will disappear.</p> <p>Click me away!</p> <p>Click me too!</p> </body> </html> |
Example 2) Call a URL, and show its response
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script> <script> var fd = new FormData(); fd.append( 'file', input.files[0] ); jQuery.ajax({ url: 'http://example.com/script.php', type: 'POST', data: fd, processData: false, contentType: false, async: false, success: function(response){ alert(response); } }); </script> |
Example 2) Call a URL, and use its Json object
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script> <script> var fd = new FormData(); fd.append( 'file', input.files[0] ); jQuery.ajax({ url: 'http://example.com/script.php', type: 'POST', data: fd, processData: false, contentType: false, async: false, success: function(response){ var obj=JSON.parse(response); alert( obj.result[0].message); } }); </script> |