I'm trying to get both blur and keypress(13) to do the same thing on an element that has been appended. An obvious use for trigger(), right? Not working. I'm hoping I'm just being stupid and missing something obvious.
$(document).ready (function() {
$("#btn").click (function() {
$("#this-ul").append ("<li><input id='input1' type='text'></li><li><input type='text' id='input2'></li>");
$("#input1").focus();
});
$("#this-ul").on ("blur", "#input1", function() {
$("#input2").val ("blurred");
});
$("#this-ul").on ("keypress", "#input1", function (e) {
if (e.which == 13) {
// Want to trigger $("#this-ul").on ("blur"...) as above
}
});
});
<script src="//code.jquery.com/jquery-1.11.3.min.js"></script>
<button id="btn" type="button">Click</button>
<ul id="this-ul"></ul>