I do not understand what does stopPropagation do.Why i need to use stopPropagation() in this code?. If i don't use it the enter key doesn't work the first time. Here is the code: http://codepen.io/Juan1417/pen/XNJeWd
$(document).ready(function () {
$("#searchTerm").keypress(function (e) {
if (e.which == 13) {
$("#search").click();
**e.stopPropagation();**
return false;
}
});
$("#search").click(function () {
var searchTerm = $("#searchTerm").val();
var url = "https://en.wikipedia.org/w/api.php?action=opensearch&search=" + searchTerm + "&format=json&callback=?";
$.ajax({
type: "GET",
url: url,
async: false,
dataType: "json",
success: function (data) {
for (var i = 0; i < data[1].length; i++) {
$("#output").prepend("<li><a href=" + data[3][i] + " target='_blank'>" + data[1][i] + "</a><br><span>" + data[3][i] + "</span><br>" + data[2][i] + "</p></li>");
}
},
error: function (errorMessage) {
alert(errorMessage);
}
});
});
});