jQuery to pure Javascript examples – 5

Get inner text // jQuery var text = $(“#myElm”).text(); // Pure javascript var text = document.getElementById(“myElm”).textContent; Set inner text // jQuery $(“#myElm”).text(“My text”); // Pure javascript document.getElementById(“myElm”).textContent = “My text”; Get inner HTML // jQuery…

jQuery to pure Javascript examples – 4

Add onclick event // jQuery $(“#myElm”).click(function(){ alert(“Hello world”); }); // Pure javascript document.getElementById(“myElm”).addEventListener(“click”, function() { alert(“Hello world!”); }, false); Get child node by index //jQuery var child = $(“#myElm”).eq(2); // Pure javascript var child =…

jQuery to pure Javascript examples – 3

In these examples we see how easy it is to display, hide or use the toggle without jQuery. Hide an item  // jQuery $(“#myElm”).hide(); // Pure javascript document.getElementById(“myElm”).style.display = “none”; Show an item // jQuery…

jQuery to pure Javascript examples – 2

With this post we continue the series of examples to replace jQuery with pure javascript. Add class // jQuery $(“#myElm”).addClass(“my-class”); // Pure Javascript document.getElementById(“myElm”).classList.add(“my-class”); Remove class from an element // jQuery $(“#myElm”).removeClass(“my-class”); // Pure Javascript…

Get query string parameters with jQuery

$.urlParam = function (name) { var results = new RegExp(‘[\?&]’ + name + ‘=([^&#]*)’) .exec(window.location.href); if (results == null) { return 0; } return results[1] || 0; } console.log($.urlParam(‘dotmaui’)); //cool

Examples of Ajax requests with jQuery

jQuery simplifies our life a lot, even with Ajax requests, here’s an example of a basic request: $.ajax({ url: ‘myfile.php’, success:function(data){ alert(data); } }); This is the simplest possible Ajax request, if our request is…

SambucaJS – jQuery plugin

Small jquery plugin that adds some functionality to jquery, eg: Check if an item is empty Check whether an item exists Take a parameter in the querystring of the current Web page. /*! * jQuery…