To create an attribute for an HTML tag, sometimes we need to add this:
yourTag.src yourTag.src = 'http://lolxd.com/404.png'
But there are special attributes, and they have different editing methods:
yourTag.classList yourTag.className
And there is an onclick
attribute that can use it like this:
// The first way obj.onclick = function () { alert('lalala') } // With the Event Listener obj.addEventListener('click', function () { alert('lalala') }, false) // Or, a text-render way obj.setAttribute('onclick', 'alert(`lalala`)')
I recommend you a way to listen to events, but try everything: D
Juan David Castro
source share