{"flag":true,"single":true,"pageTitle":"JQUERY CheatSheet","post":{"id":217,"user_id":"1","slug":"jquery-cheatsheet-ksag","title":"JQUERY CheatSheet","body":"<p>jQuery is a lightweight, \"write less, do more\", JavaScript library.&nbsp;jQuery is a JavaScript Library, simple, and easy. We can with JQuery<\/p>\r\n<p>&gt;HTML\/DOM manipulation<br>&gt;CSS manipulation<br>&gt;HTML event methods<br>&gt;Effects and animations<br>&gt;AJAX<br>&gt;Utilities<\/p>\r\n<p style=\"text-align: center;\"><span style=\"text-decoration: underline;\"><span style=\"font-size: 14pt;\"><strong>1.GET STARTED<\/strong><\/span><\/span><\/p>\r\n<p><span style=\"font-size: 12pt;\">Download from here <strong><a href=\"http:\/\/jquery.com\/download\/\">http:\/\/jquery.com\/download\/<\/a> <\/strong>and add it into your project<\/span><\/p>\r\n<pre class=\"language-markup\"><code>&lt;head&gt;\r\n   &lt;script src=\"jquery-3.7.1.min.js\"&gt;&lt;\/script&gt;\r\n&lt;\/head&gt;<\/code><\/pre>\r\n<p>Or Use Google CDN in head Tag<\/p>\r\n<pre class=\"language-markup\"><code>&lt;script src=\"https:\/\/ajax.googleapis.com\/ajax\/libs\/jquery\/3.7.1\/jquery.min.js\"&gt;&lt;\/script&gt;<\/code><\/pre>\r\n<p style=\"text-align: center;\"><span style=\"text-decoration: underline;\"><strong><span style=\"font-size: 14pt;\">2. JQUERY SYNTAX<\/span><\/strong><\/span><\/p>\r\n<p>Basic syntax is:&nbsp;<\/p>\r\n<pre class=\"language-markup\"><code>$(selector).action()<\/code><\/pre>\r\n<p>&nbsp;<\/p>\r\n<p><strong>$<\/strong> to define\/access jQuery ,&nbsp;(selector) to find HTML elements,&nbsp;action() to be performed on the element(s)<\/p>\r\n<p>&gt;&gt; To <strong>prevent any jQuery code<\/strong> from running before the<strong> document is finished loading<\/strong> use (is ready). It will allow code when all elements created and all images loaded properly<\/p>\r\n<pre class=\"language-markup\"><code>$(document).ready(function(){\r\n  \/\/ jQuery methods go here...\r\n});<\/code><\/pre>\r\n<p>OR use shorter syntax<\/p>\r\n<pre class=\"language-markup\"><code>$(function(){\r\n  \/\/ jQuery methods go here...\r\n});<\/code><\/pre>\r\n<p style=\"text-align: center;\"><span style=\"font-size: 14pt;\"><strong><span style=\"text-decoration: underline;\">3. SELECTORS IN JQUERY<\/span><br><\/strong><\/span><\/p>\r\n<p><strong>1.select elements IE paragraph element<\/strong><\/p>\r\n<pre class=\"language-markup\"><code>$(\"p\");<\/code><\/pre>\r\n<p><strong>2. <\/strong>select element that has id test ie<strong> &lt;div id=\"test\"&gt; Hello&lt;\/div&gt;<\/strong><\/p>\r\n<pre class=\"language-markup\"><code>$(\"#test\")<\/code><\/pre>\r\n<p><strong>3. <\/strong>select element that has class test <strong>&lt;div class=\"test\"&gt;hello &lt;\/div&gt;<\/strong><\/p>\r\n<pre class=\"language-markup\"><code>$(\".test\")<\/code><\/pre>\r\n<p><strong>4. <\/strong>More Examples of jQuery Selectors<\/p>\r\n<pre class=\"language-javascript\"><code>$(\"*\")\t                          Selects all elements\t\r\n$(this)\t                          Selects the current HTML element\t\r\n$(\"p.intro\")\t                  Selects all &lt;p&gt; elements with class=\"intro\"\t\r\n$(\"p:first\")\t                  Selects the first &lt;p&gt; element\t\r\n$(\"ul li:first\")\t                  Selects the first &lt;li&gt; element of the first &lt;ul&gt;\t\r\n$(\"ul li:first-child\")\t          Selects the first &lt;li&gt; element of every &lt;ul&gt;\t\r\n$(\"[href]\")\t                  Selects all elements with an href attribute\t\r\n$(\"a[target='_blank']\")\t  Selects all &lt;a&gt; elements with a target attribute value equal to \"_blank\"\t\r\n$(\"a[target!='_blank']\")\t  Selects all &lt;a&gt; elements with a target attribute value NOT equal to \"_blank\"\t\r\n$(\":button\")\t                  Selects all &lt;button&gt; elements and &lt;input&gt; elements of type=\"button\"\t\r\n$(\"tr:even\")\t                  Selects all even &lt;tr&gt; elements\t\r\n$(\"tr:odd\")\t                  Selects all odd &lt;tr&gt; elements\r\n$(\":radio\");\t                  All input type=radio\r\n$('input[type=\"radio\"][value=\"option2\"]').prop('checked', true);  \/\/enable check on radio input based on value<\/code><\/pre>\r\n<p><strong>5. <\/strong>select more than one elements<\/p>\r\n<pre class=\"language-markup\"><code>$(\".class1\",\".class2\");<\/code><\/pre>\r\n<p style=\"text-align: center;\"><span style=\"text-decoration: underline;\"><span style=\"font-size: 14pt;\"><strong>4. EVENTS IN JQUERY<\/strong><\/span><\/span><\/p>\r\n<p><strong>syntax:<\/strong><\/p>\r\n<pre class=\"language-markup\"><code>$(\"p\").event(function(){\r\n   \/\/CODE HERE\r\n});<\/code><\/pre>\r\n<p><strong>1. Binding<\/strong><\/p>\r\n<pre class=\"language-markup\"><code>$(selector).bind(event, data, function);<\/code><\/pre>\r\n<pre class=\"language-markup\"><code>        function handlerName(e) { \r\n            alert(e.data.msg); \r\n        }\r\n        $(document).ready(function() { \r\n            $(\"p\").bind(\"click\",{ msg: \"You just clicked the paragraph!\"},handlerName) \r\n        }); <\/code><\/pre>\r\n<p><strong>2.on change input feild<\/strong><\/p>\r\n<pre class=\"language-markup\"><code>$(selector).change(function(){});<\/code><\/pre>\r\n<p><strong>3.Get x-axis or y-axis point<\/strong><\/p>\r\n<pre class=\"language-markup\"><code>$(document).mousemove(function(event) { \r\n\talert(\"X= \" + event.pageX); \r\n\talert(\"Y= \" + event.pageY); \r\n});<\/code><\/pre>\r\n<p><strong>4.Return node name<\/strong><\/p>\r\n<pre class=\"language-markup\"><code>$(\"body\").click(function(event) { \r\n        $(\"#output\").html(\"clicked: \" + event.target.nodeName); \r\n}); <\/code><\/pre>\r\n<p><strong>5.when event is used<\/strong><\/p>\r\n<pre class=\"language-markup\"><code>$(\"#div1\").on(\"click dblclick mouseover mouseout\",function(event) { \r\n      $(\".div2\").html(\"Event: \" + event.type); \r\n}); <\/code><\/pre>\r\n<p><strong>6.return which keyboard key or mouse button was pressed<\/strong><\/p>\r\n<pre class=\"language-markup\"><code>$(\"input\").keydown(function(event) { \r\n      alert(\"Key: \" + event.which);\r\n});<\/code><\/pre>\r\n<p><strong>7. when focus on some element ie when click inside input fiels<\/strong><\/p>\r\n<pre class=\"language-markup\"><code>$(selector).focus(function(){});<\/code><\/pre>\r\n<p><strong>8.gain focus on element<\/strong><\/p>\r\n<pre class=\"language-markup\"><code>$(selector).focusin(function);<\/code><\/pre>\r\n<p><strong>9.remove focus<\/strong><\/p>\r\n<pre class=\"language-markup\"><code>$(selector).focusout(function);<\/code><\/pre>\r\n<p><strong>10.mousein &amp; mouse out<\/strong><\/p>\r\n<pre class=\"language-markup\"><code>$(selector).hover(function(){},function(){});<\/code><\/pre>\r\n<p><strong>11.when a keybord key is pressed down<\/strong><\/p>\r\n<pre class=\"language-markup\"><code>$(document).keydown(function(event) { \r\n    var key =event.keyCode; \/\/event.which\r\n \talert(key);\r\n}); <\/code><\/pre>\r\n<p><strong>12.to check key is pressed or not.<\/strong><\/p>\r\n<pre class=\"language-markup\"><code>$(selector).keypress(function([event]){});<\/code><\/pre>\r\n<p><strong>13.when key is released<\/strong><\/p>\r\n<pre class=\"language-markup\"><code>$(selector).keyup(function([event]){}); <\/code><\/pre>\r\n<p><strong>14.when left mouse button is pressed<\/strong><\/p>\r\n<pre class=\"language-markup\"><code>$(selector).mousedown(function(){});<\/code><\/pre>\r\n<p><strong>15.when mouse enters into selected element<\/strong><\/p>\r\n<pre class=\"language-markup\"><code>$(selector).mouseenter(function(){});<\/code><\/pre>\r\n<p><strong>16.when mouse pointer moves over the selected element.<\/strong><\/p>\r\n<pre class=\"language-markup\"><code>$(selector).mousemove(function(){});<\/code><\/pre>\r\n<p><strong>17.when mouse pointer moves out from the selected element.<\/strong><\/p>\r\n<pre class=\"language-markup\"><code>$(selector).mouseout(function(){});<\/code><\/pre>\r\n<p><strong>18.when mouse pointer moves over the selected elements.<\/strong><\/p>\r\n<pre class=\"language-markup\"><code>$(selector).mouseover(function(){});<\/code><\/pre>\r\n<p><strong>19.when left button of mouse is realeased<\/strong><\/p>\r\n<pre class=\"language-markup\"><code>$(selector).mouseup(function(){});<\/code><\/pre>\r\n<p><strong>20.when window resized<\/strong><\/p>\r\n<pre class=\"language-markup\"><code>$(selector).resize(function(){});<\/code><\/pre>\r\n<p><strong>21.when scroll element or body<\/strong><\/p>\r\n<pre class=\"language-markup\"><code>$(selector).scroll(function(){});<\/code><\/pre>\r\n<p><strong>22.remove event<\/strong><\/p>\r\n<pre class=\"language-markup\"><code>$(selector).undelegate(selector, event, function);<\/code><\/pre>\r\n<p><strong>23.load data from server and returned into selected element<\/strong><\/p>\r\n<p><strong>$(selector).load(URL, data, callback);<\/strong><\/p>\r\n<pre class=\"language-markup\"><code>$(\"#div_content\").load(\"gfg.txt\");<\/code><\/pre>\r\n<pre class=\"language-markup\"><code>$(\"#div_content\").load(\"gfg.txt\", function(response, status, http){ \r\n        if(status == \"success\"){}\r\n        if(status == \"error\"){alert(\"Error: \" + http.status + \": \"+ http.statusText);}\r\n    }); \r\n\r\n<\/code><\/pre>\r\n<p><strong>24.when leave input feild<\/strong><\/p>\r\n<pre class=\"language-markup\"><code>$(selector).blur(function(){});<\/code><\/pre>\r\n<p><strong>25.when click on element etc \/\/also used for live elements ie if &lt;li&gt; added by jquery then click event is not working on that so use on<\/strong><\/p>\r\n<pre class=\"language-markup\"><code>$(selector).on({event:function(){},event2:function(){},...});<\/code><\/pre>\r\n<p><strong>Syntax:&nbsp;<\/strong><strong>.on( events [, selector ] [, data ], handler )<\/strong><\/p>\r\n<pre class=\"language-markup\"><code>$( \"# tr\" ).on( \"click\", function() {\r\n  console.log( $( this ).text() );\r\n});<\/code><\/pre>\r\n<p><strong>For dynamic code that are generated by js<\/strong><\/p>\r\n<pre class=\"language-markup\"><code>$(document).on('click', '.cnicis', function() {\r\n\tconsole.log('sss');\r\n});<\/code><\/pre>\r\n<p>26.when double click on element<\/p>\r\n<pre class=\"language-markup\"><code>$(selector).dblclick(function(){});<\/code><\/pre>\r\n<p style=\"text-align: center;\"><span style=\"text-decoration: underline;\"><span style=\"font-size: 14pt;\"><strong>5. <span style=\"font-size: 14pt;\">Effects , hide,show, fades , slides , animate ,callback ,chaning ,delay<\/span><\/strong><\/span><\/span><\/p>\r\n<p><strong>1.Hide &amp; Show<\/strong><\/p>\r\n<p>$(selector).hide(speed,callback); <strong>\/\/hide the element<\/strong><\/p>\r\n<p>$(selector).show(speed,callback); <strong>\/\/show the element<\/strong><\/p>\r\n<p>$(selector).toggle(speed,callback); <strong>\/\/show if the element is hidden &amp; vv<\/strong><\/p>\r\n<pre class=\"language-markup\"><code>$(\"p\").hide(1000);<\/code><\/pre>\r\n<p><strong>2. Fades<\/strong><\/p>\r\n<p>$(selector).fadeIn(speed,callback);<\/p>\r\n<p>$(selector).fadeOut(speed,callback);<\/p>\r\n<p>$(selector).fadeToggle(speed,callback);<\/p>\r\n<p>$(selector).fadeTo(speed,opacity,callback); \/\/opacity is added in fadding<\/p>\r\n<pre class=\"language-markup\"><code>$(\"#div3\").fadeIn(3000);\r\n$(\"#div2\").fadeTo(\"slow\", 0.4);<\/code><\/pre>\r\n<p><strong>3. Slides<\/strong><\/p>\r\n<p>$(selector).slideDown(speed,callback); <strong>\/\/slide down an element<\/strong><\/p>\r\n<p>$(selector).slideUp(speed,callback); <strong>\/\/slide up an element<\/strong><\/p>\r\n<p>$(selector).slideToggle(speed,callback); <strong>\/\/toggle b\/w slide down and slide up<\/strong><\/p>\r\n<p><strong>4. Animate<\/strong><\/p>\r\n<p>$(selector).animate({params},speed,callback);<\/p>\r\n<pre class=\"language-markup\"><code>\t$(\"button\").click(function(){\r\n\t  $(\"div\").animate({\r\n\t    left: '250px',\r\n\t    opacity: '0.5',\r\n\t    paddingLeft:'5px', \/\/use camel case properties\r\n\t    height: '+=150px', \/\/we can also use relative values\r\n\t    height: 'toggle' \/\/we can also use properties now element height will be between 0-n\r\n\t  });\r\n\t});<\/code><\/pre>\r\n<p><strong>use queue to execute different animations after each other<\/strong><\/p>\r\n<pre class=\"language-markup\"><code>\t$(\"button\").click(function(){\r\n\t  var div = $(\"div\");\r\n\t  div.animate({height: '300px', opacity: '0.4'}, \"slow\");\r\n\t  div.animate({width: '300px', opacity: '0.8'}, 2000);\r\n\t  div.animate({height: '100px', opacity: '0.4'}, \"fast\");\r\n\t}); <\/code><\/pre>\r\n<p><strong>stop: to stop animations<\/strong><\/p>\r\n<p>$(selector).stop([stopAll,goToEnd]);<\/p>\r\n<ul>\r\n<li>stopAll:true|false <strong>\/\/if false stop current queue else all queue<\/strong><\/li>\r\n<li>goToEnd:true|false<strong> \/\/complete current animation immediately<\/strong><\/li>\r\n<li>both has default false value.<\/li>\r\n<\/ul>\r\n<p><strong>CallBack<\/strong><\/p>\r\n<p>A callback function is executed after the current effect is finished.<\/p>\r\n<p><strong>syntax: $(selector).hide(speed,callback);<\/strong><\/p>\r\n<pre class=\"language-markup\"><code>\t$(\"p\").hide(\"slow\", function(){\r\n\t    alert(\"The paragraph is now hidden\");\r\n\t  });\r\n\r\n<\/code><\/pre>\r\n<p>it ll first hide &lt;p&gt; then alert, by default alert is executed first<\/p>\r\n<p><strong>Chaning:<\/strong> use multiple jquery methods at same time w\/o selecting element multiple times<\/p>\r\n<pre class=\"language-markup\"><code>$(\"#p1\").css(\"color\", \"red\").slideUp(2000).slideDown(2000);<\/code><\/pre>\r\n<p><strong>Delay:<\/strong> delay and then execute<\/p>\r\n<pre class=\"language-markup\"><code>$(\"#d3\").delay(1000).fadeIn();<\/code><\/pre>\r\n<p style=\"text-align: center;\"><span style=\"text-decoration: underline;\"><span style=\"font-size: 14pt;\"><strong>6. JQUERY HTML Get elements, Set elements, Add elements, remove elemets, CSS set,get, Dimentions<\/strong><\/span><\/span><\/p>\r\n<p><strong>1. GET HTML ELEMENTS<\/strong><\/p>\r\n<p>$(selector).text(); <strong>\/\/ get plain text of element<\/strong><\/p>\r\n<p>$(selector).html(); <strong>\/\/ get html of element<\/strong><\/p>\r\n<p>$(selector).val(); <strong>\/\/ value of form fields<\/strong><\/p>\r\n<p>$(selector).attr(\"atributeName\"); <strong>\/\/get attribute name<\/strong><\/p>\r\n<p><strong>2. SET HTML ELEMENTS<\/strong><\/p>\r\n<p>$(selector).text(\"hello\"); <strong>\/\/set text of element<\/strong><\/p>\r\n<p>$(selector).html(\"&lt;p&gt;hy&lt;\/p&gt;\");<\/p>\r\n<p>$(selector).val(\"Enter Name\");<\/p>\r\n<p>$(selector).attr(\"atributeName\",\"value\");<\/p>\r\n<pre class=\"language-markup\"><code>$(\"#rizi\").attr(\"href\",\"gondal\");<\/code><\/pre>\r\n<p>For Multiple Attributes<\/p>\r\n<pre class=\"language-markup\"><code>$(\"#w3s\").attr({\r\n   \"href\" : \"https:\/\/www.google.com\/\",\r\n   \"title\" : \"Google\"\r\n});<\/code><\/pre>\r\n<p><strong>3. ADD NEW DATA<\/strong><\/p>\r\n<p>$(selector).append(\"insert content at end of selected element\"); <strong>\/\/text or html added<\/strong><\/p>\r\n<p>$(selector).prepend(\"insert content at begning of selected\");<\/p>\r\n<p>$(selector).after(\"insert content after selected element\");<\/p>\r\n<p>$(selector).before(\"insert content before selected element\");<\/p>\r\n<pre class=\"language-php\"><code>var txt1 = \"&lt;p&gt;Text.&lt;\/p&gt;\";               \/\/ Create element with HTML \r\nvar txt2 = $(\"&lt;p&gt;&lt;\/p&gt;\").text(\"Text.\");   \/\/ Create with jQuery\r\nvar txt3 = document.createElement(\"p\");  \/\/ Create with DOM\r\ntxt3.innerHTML = \"Text.\";\r\n$(\"body\").append(txt1, txt2, txt3);      \/\/ Append the new elements<\/code><\/pre>\r\n<p><strong>4. REMOVE DATA<\/strong><\/p>\r\n<p>$(selector).remove();<strong>\/\/remove selected element and its childs<\/strong><\/p>\r\n<p>$(selector).empty();<strong>\/\/remove childs of selected element<\/strong><\/p>\r\n<p>ie $(\"p\").remove(\".test\");<strong>\/\/remove all p elements that has class .test<\/strong><\/p>\r\n<p><strong>5. CSS<\/strong><\/p>\r\n<p>$(selector).addClass(\"Classname1 class2\");<\/p>\r\n<p>$(selector).removeClass(\"class\");<\/p>\r\n<p>$(selector).toggleClass(\"class\"); \/\/if active then remove &amp;vv<\/p>\r\n<pre class=\"language-javascript\"><code>$(\"p\").css(\"background-color\");\/\/get background color\r\n$(selector).css(\"propertyname\",\"value\"); \/\/set css values\r\n$(selector).css({\"propertyname\":\"value\",\"propertyname\":\"value\",...});\/\/set multiple css values<\/code><\/pre>\r\n<p><strong>6. DIMENTIONS<\/strong><\/p>\r\n<p>$(selector).width(); <strong>\/\/width of element exclude padding,margin,border ie $(\"div\").width();<\/strong><\/p>\r\n<p>$(selector).height();<strong> \/\/height of element exclude padding,margin,border<\/strong><\/p>\r\n<p>$(selector).innerWidth();<strong> \/\/ width includes padding<\/strong><\/p>\r\n<p>$(selector).innerHeight();<strong> \/\/height includes padding<\/strong><\/p>\r\n<p>$(selector).outerWidth(); <strong>\/\/full width of element<\/strong><\/p>\r\n<p>$(selector).outerHeight();<strong> \/\/full height of element<\/strong><\/p>\r\n<p>$(document||window||\"p\").width();<\/p>\r\n<p style=\"text-align: center;\"><span style=\"text-decoration: underline;\"><span style=\"font-size: 14pt;\"><strong>7. Traversing:Ancestors, Descendants, Siblings,Filtering, Traversing methods<\/strong><\/span><\/span><\/p>\r\n<p><strong>1. Ancestors: PARDADA<\/strong><\/p>\r\n<p>$(selector).parent(); <strong>\/\/parent of element<\/strong><\/p>\r\n<p>$(selector).parents(); <strong>\/\/all parents upto root html<\/strong><\/p>\r\n<p>$(selector).parentsUntil(\"body\"); <strong>\/\/current to body tag parents<\/strong><\/p>\r\n<p>$(\"selector\").closest(\"ul\").css({\"color\": \"red\", \"border\": \"2px solid red\"});&nbsp; \/\/ jo phla bab, dada ya jo b find hwa,&nbsp;<strong><br><\/strong><\/p>\r\n<p>ie<\/p>\r\n<pre class=\"language-markup\"><code>&lt;div&gt;\r\n\t&lt;tr&gt;\r\n\t\t&lt;td&gt;mogo&lt;\/td&gt;\r\n\t\t&lt;td&gt;&lt;a href=\"123\" class=\"123\"&gt;&lt;\/a&gt;&lt;\/td&gt;\r\n\t&lt;\/tr&gt;\r\n&lt;\/div&gt;\r\n\r\n&lt;script&gt;\r\n$(document).on('click', 'a', function (e) {\r\n    e.preventDefault(); \/\/ Prevent the default behavior of the anchor tag\r\n    $(this).closest('tr').remove(); \/\/ Remove the closest &lt;tr&gt; element\r\n});\r\n&lt;\/script&gt;<\/code><\/pre>\r\n<p>&nbsp;<\/p>\r\n<p><strong>2. Descendants: AULAAD<\/strong><\/p>\r\n<p>$(selector).children(); <strong>\/\/all direct childs only<\/strong><\/p>\r\n<p>$(selector).find(); <strong>\/\/return all descendants ie $(\"div\").find(\"*\");<\/strong><\/p>\r\n<p>$(selector).contents(); <strong>\/\/all direct childs only with comments also<\/strong><\/p>\r\n<pre class=\"language-markup\"><code>$(\"div\").children(\"p.first\")<\/code><\/pre>\r\n<p><strong>3. Siblings: That has same parent<\/strong><\/p>\r\n<p>$(selector).siblings(); <strong>\/\/all siblings , ie siblings(\"p\")<\/strong><\/p>\r\n<p>$(selector).next(); <strong>\/\/one next sibling<\/strong><\/p>\r\n<p>$(selector).nextAll();<strong> \/\/all next siblings<\/strong><\/p>\r\n<p>$(selector).nextUntil(\"h2\"); <strong>\/\/current to h2 siblings<\/strong><\/p>\r\n<p>$(selector).prev(); <strong>\/\/one previous siblings<\/strong><\/p>\r\n<p>$(selector).prevAll();<strong> \/\/all previous siblings<\/strong><\/p>\r\n<p>$(selector).prevUntil(\"h2\"); <strong>\/\/current to previous h2 sibling<\/strong><\/p>\r\n<p><strong>4. Filtering: find elements using positions<\/strong><\/p>\r\n<p>$(selector).first(); <strong>\/\/ ie first(\"div\"); find first div in document<\/strong><\/p>\r\n<p>$(selector).last(); <strong>\/\/ ie last(\"div\"); find last div in document<\/strong><\/p>\r\n<p>$(selector).eq(n);&nbsp;<strong> \/\/element with index n find ie $(\"div\").eq(0) find first div in document<\/strong><\/p>\r\n<p>$(selector).filter(\"criteria\");<strong> \/\/ie (\"p\").filter(\".cl\") \/\/find all p elements that have class cl<\/strong><\/p>\r\n<p>$(selector).not(\"criteria\"); <strong>\/\/ie (\"p\").not(\".cl\") \/\/find all p elements that have not class cl<\/strong><\/p>\r\n<p><strong>5. Traversing methods:<\/strong><\/p>\r\n<p>$(selector).$(\"p\").has(\"span\"); <strong>\/\/return all elements that have span element<\/strong><\/p>\r\n<p>$(selector).each(function(index,element));&nbsp;<\/p>\r\n<pre class=\"language-javascript\"><code>$(\"li\").each(function(){ \r\n   alert($(this).text());\r\n });<\/code><\/pre>\r\n<p>$(selector).slice(2); <strong>\/\/ select all elements but first 2 (0,1 index)<\/strong><\/p>\r\n<p><strong>Check if p parent is div<\/strong><\/p>\r\n<pre class=\"language-markup\"><code>if ($(\"p\").parent().is(\"div\"));<\/code><\/pre>\r\n<p style=\"text-align: center;\"><span style=\"text-decoration: underline;\"><span style=\"font-size: 14pt;\"><strong>8. AJAX In JQuery<\/strong><\/span><\/span><\/p>\r\n<p>AJAX = Asynchronous JavaScript and XML.&nbsp;In short; AJAX is about loading data in the background and display it on the webpage, without reloading the whole page.<\/p>\r\n<p><strong>1. load method <\/strong>$(selector).load(URL,data,callback);<\/p>\r\n<p>The load() method loads data from a server and puts the returned data into the selected element.<\/p>\r\n<pre class=\"language-markup\"><code>$(\"#div1\").load(\"demo_test.txt\");<\/code><\/pre>\r\n<pre class=\"language-markup\"><code>$(\"button\").click(function(){\r\n  $(\"#div1\").load(\"demo_test.txt\", function(responseTxt, statusTxt, xhr){\r\n    if(statusTxt == \"success\")\r\n      alert(\"External content loaded successfully!\");\r\n    if(statusTxt == \"error\")\r\n      alert(\"Error: \" + xhr.status + \": \" + xhr.statusText);\r\n  });\r\n});<\/code><\/pre>\r\n<p><strong>2. HTTP Requests using Ajax<\/strong><\/p>\r\n<table style=\"border-collapse: collapse; width: 100%;\" border=\"1\"><colgroup><col style=\"width: 49.9592%;\"><col style=\"width: 49.9592%;\"><\/colgroup>\r\n<tbody>\r\n<tr>\r\n<td><strong>GET -<\/strong> Requests data from a specified resource<\/td>\r\n<td><strong>POST -<\/strong> Submits data to be processed to a specified resource<\/td>\r\n<\/tr>\r\n<tr>\r\n<td><strong>GET <\/strong>is basically used for just getting (retrieving) some data from the server.<\/td>\r\n<td><strong>POST <\/strong>can also be used to <strong>get some data<\/strong> from the server. However, the POST method<strong> NEVER caches data<\/strong>, and is often used to <strong>send data along <\/strong>with the request.<\/td>\r\n<\/tr>\r\n<\/tbody>\r\n<\/table>\r\n<p>&gt;&gt; <strong>GET Method <\/strong>$.get(URL,callback);<\/p>\r\n<pre class=\"language-markup\"><code>$(\"button\").click(function(){\r\n  $.get(\"demo_test.asp\", function(data, status){\r\n    alert(\"Data: \" + data + \"\\nStatus: \" + status);\r\n  });\r\n});<\/code><\/pre>\r\n<p><strong>&gt;&gt; POST method&nbsp;<\/strong><\/p>\r\n<pre class=\"language-markup\"><code>$(\"button\").click(function(){\r\n  $.post(\"demo_test_post.asp\",\r\n  {\r\n    name: \"Donald Duck\",\r\n    city: \"Duckburg\"\r\n  },\r\n  function(data, status){\r\n    alert(\"Data: \" + data + \"\\nStatus: \" + status);\r\n  });\r\n});<\/code><\/pre>\r\n<p style=\"text-align: center;\"><span style=\"text-decoration: underline; font-size: 14pt;\"><strong>9. JQuery Filter Table searches<\/strong><\/span><\/p>\r\n<pre class=\"language-markup\"><code>&lt;script&gt;\r\n$(document).ready(function(){\r\n  $(\"#myInput\").on(\"keyup\", function() {\r\n    var value = $(this).val().toLowerCase();\r\n    $(\"#myTable tr\").filter(function() {\r\n      $(this).toggle($(this).text().toLowerCase().indexOf(value) &gt; -1)\r\n    });\r\n  });\r\n});\r\n&lt;\/script&gt;<\/code><\/pre>\r\n<p><a href=\"https:\/\/www.w3schools.com\/jquery\/jquery_ref_ajax.asp\">https:\/\/www.w3schools.com\/jquery\/jquery_ref_ajax.asp<\/a><\/p>\r\n<p style=\"text-align: center;\"><span style=\"font-size: 14pt;\"><strong>10. Jquery No Conflit<\/strong><\/span><\/p>\r\n<p>jQuery uses the <strong>$<\/strong> sign as a shortcut for jQuery. There are many other popular JavaScript frameworks that use <strong>$ <\/strong>also.<\/p>\r\n<p>The <strong>noConflict() method<\/strong> releases the hold on the $ shortcut identifier, so that other scripts can use it.<\/p>\r\n<pre class=\"language-markup\"><code>$.noConflict();\r\njQuery(document).ready(function(){\r\n  jQuery(\"button\").click(function(){\r\n    jQuery(\"p\").text(\"jQuery is still working!\");\r\n  });\r\n});<\/code><\/pre>\r\n<p>You can also create your own shortcut very easily. The noConflict() method returns a reference to jQuery, that you can save in a variable, for later use. Here is an example:<\/p>\r\n<pre class=\"language-markup\"><code>var jq = $.noConflict();\r\njq(document).ready(function(){\r\n  jq(\"button\").click(function(){\r\n    jq(\"p\").text(\"jQuery is still working!\");\r\n  });\r\n});<\/code><\/pre>\r\n<p>If you have a block of jQuery code which uses the $ shortcut and you do not want to change it all, you can pass the $ sign in as a parameter to the ready method.<\/p>\r\n<pre class=\"language-markup\"><code>$.noConflict();\r\njQuery(document).ready(function($){\r\n  $(\"button\").click(function(){\r\n    $(\"p\").text(\"jQuery is still working!\");\r\n  });\r\n});<\/code><\/pre>","category_id":"28","is_private":"0","created_at":"2023-10-14T00:33:45.000000Z","updated_at":"2025-01-22T02:30:20.000000Z","category":{"id":28,"user_id":"1","name":"Jquery","slug":"jquery-k1v4","parent_id":"12","created_at":"2023-11-10T01:48:35.000000Z","updated_at":"2023-11-10T01:48:35.000000Z"},"user":{"id":1,"name":"R GONDAL","email":"rizikmw@gmail.com","email_verified_at":null,"two_factor_confirmed_at":null,"current_team_id":"1","profile_photo_path":null,"created_at":"2023-03-12T10:49:33.000000Z","updated_at":"2025-01-10T12:59:00.000000Z","profile_photo_url":"https:\/\/ui-avatars.com\/api\/?name=R+G&color=7F9CF5&background=EBF4FF"}},"pageDesc":"jQuery is a lightweight, \"write less, do more\", JavaScript library.&nbsp;jQuery is a JavaScript Library, simple, and easy. We can with JQuer - JQUERY CheatSheet (Updated: January 22, 2025) - Read more about JQUERY CheatSheet at my programming site [SITE]","categories":[]}