Created
June 7, 2016 15:55
-
-
Save nonZero/9d3a9c794d068423c14f516f19ce42fd to your computer and use it in GitHub Desktop.
$(".parent").on("click", "child", ....)
This file contains 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
<!DOCTYPE html> | |
<html> | |
<head> | |
<title>JS DEMO</title> | |
</head> | |
<body> | |
<input type="text" class="ttt"/> | |
<button class="add-note">add</button> | |
<ul class="notes"> | |
<li>milk</li> | |
<li class="sweet liquid">honey</li> | |
<li class="sweet">cookies</li> | |
<li>coffee</li> | |
</ul> | |
<script src="jquery-2.2.4.js"></script> | |
<script src="index.js"></script> | |
</body> | |
</html> |
This file contains 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
console.log("start"); | |
$('.ttt').on('input', function() { | |
console.log($(this).val()); | |
}); | |
$(".add-note").click(function () { | |
$(".notes").append($("<li/>").text("hahahaha")); | |
}); | |
$("ul.notes").on('click', 'li', function () { | |
// Attach the evnent to the ul, | |
// it will work on li inside it. | |
$(this).css('background', 'orange'); | |
}); | |
console.log("end"); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment