I have this button <button id='a'></button> which I trigger its click by js document.getElementById('a').onclick=function(){alert('Hello world');}.
How to append code to this function inside the tag like this <button id='a' onclick='this.onclick; alert('hello 2');'></button>
You can call addEventListener to add more click listeners in addition to the onclick handler originally assigned in the HTML. Done this way, both handlers will execute when you click the button.
document.getElementById('a').addEventListener('click', function() {
alert('2');
});
<button id="a" onclick="alert('1')">Test</button>