-
-
Save boppy/ad8b87be2868b273ce8f3a898bf85df5 to your computer and use it in GitHub Desktop.
alert the buttons text //source https://jsbin.com/fawepetaha
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<div class="btns"> | |
<p>Write JavaScript (using jQuery is fine) so that clicking on any button will cause an alert to popup with the text of the button that was clicked.</p> | |
<p>Make sure your solution is as efficient as possible even if there are a lot more <code>button.btn</code>'s added on the page. Do not use unnecessary event listeners.</p> | |
<button class="btn">c</button> | |
<button class="btn">l</button> | |
<button class="btn">o</button> | |
<button class="btn">s</button> | |
<button class="btn">e</button> | |
<button class="btn">.</button> | |
<button class="btn">i</button> | |
<button class="btn">o</button> | |
</div> | |
<script src="https://code.jquery.com/jquery-2.1.4.js"></script> | |
<script id="jsbin-javascript"> | |
// Will even work with buttons inserted after page rendering completed. ;) | |
$('div.btns').mouseup(function(e){ | |
$(e.target).is('button.btn') && alert(e.target.innerText); | |
}); | |
</script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment