Skip to content

Instantly share code, notes, and snippets.

@nonZero
Created June 7, 2016 15:55
Show Gist options
  • Save nonZero/9d3a9c794d068423c14f516f19ce42fd to your computer and use it in GitHub Desktop.
Save nonZero/9d3a9c794d068423c14f516f19ce42fd to your computer and use it in GitHub Desktop.
$(".parent").on("click", "child", ....)
<!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>
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