Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
<!DOCTYPE html>
<html>
<head>
<title>Hydra - Delete one button & produce two more!</title>
<meta charset="UTF-8">
</head>
<body id="hydrabody">
<button class="hydrahead">Hydra Head</button>
</body>
<script>
document.addEventListener('click', function(e){
if(e.target.className !=='hydrahead'){
return;
}
var bd = document.getElementById('hydrabody');
var lefthead = document.createElement('button');
var righthead = document.createElement('button');
lefthead.setAttribute('class','hydrahead');
lefthead.innerHTML = 'Left Hydra Head';
righthead.setAttribute('class','hydrahead');
righthead.innerHTML = 'Right Hydra Head';
bd.removeChild(e.target);
bd.appendChild(lefthead);
bd.appendChild(righthead);
});
</script>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.