Please vote for me, which one in the lower list is better?
I have HTML:
<div id="container"> <button class="btn">Click Here 1</button> <button class="btn">Click Here 2</button> <button class="btn">Click Here 3</button> <button class="btn">Click Here 4</button> <button class="btn">Click Here 5</button> <button class="btn">Click Here 6</button> <button class="btn">Click Here n - 2</button> <button class="btn">Click Here n - 1</button> <button class="btn">Click Here n</button> </div>
And Javascript with jQuery:
Case 1.1:
$(".btn").click(function(e){
Case 1.2:
var doSomething = function(e) {
Case 2:
$("#container").click(function(e){ if( $(e.target).is(".btn") ) {
I confuse the litle bit, what is different between them?
source share