Edit in JSFiddle

var redButton = document.getElementById('red');
var yellowButton = document.getElementById('yellow');

redButton.addEventListener('click', function() {
    console.log('RED');
    document.body.style.background = '#f00';
});

yellowButton.addEventListener('click', function() {
    console.log('YELLOW');
    setTimeout(function() {
        console.log('PAINT IT YELLOW');
        document.body.style.background = '#ff0';
    }, 0);
});

document.getElementById('reset')
    .addEventListener('click', function() {
        document.body.style.background = '';
    });

console.log('BEFORE CLICKS');
yellowButton.click();
console.log('BETWEEN CLICKS');
redButton.click();
console.log('AFTER CLICKS');
<button id="red">
RED
</button>
<button id="yellow">
YELLOW
</button>

<button id="reset">
RESET
</button>