.Maui Blog

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 = document.getElementById("myElm").childNodes.item(2);
Exit mobile version