Javascript | Trigger Change event on select
var mySelect = document.querySelector(“#mySelect”); mySelect.value = “newvalue”; mySelect.dispatchEvent(new Event(‘change’, { ‘bubbles’: true }));
var mySelect = document.querySelector(“#mySelect”); mySelect.value = “newvalue”; mySelect.dispatchEvent(new Event(‘change’, { ‘bubbles’: true }));
var jsElm = document.createElement(“script”); jsElm.type = “application/javascript”; jsElm.src = “https://cdn.dotmaui.com/libs/jquery/3.6.0/jquery.min.js”; document.head.appendChild(jsElm);
Create an Event object and pass it to the dispatchEvent method of the element: let my_element = document.getElementById(‘my_select’); let event = new Event(‘change’); my_element.dispatchEvent(event);
The code consists of three lines of Javascript:
Simply add this script to your web page: <script src=”https://cdn.dotmaui.com/p24/js/exportTableToExcel.min.js”></script> To use it, call the exportTableToExcel() function specifying the table id as the first argument and optionally the file name as the second argument. Example:…
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…
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 =…
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…
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…
With this post, we want to inaugurate a post series of examples to see how nowadays it is easy to replace jQuery with pure javascript. This is because with the new javaScript standards major web…