I'm trying to search for a word in an html file when the submit button is clicked (as far as I know my regexp is ok; it works). The problem is my code runs only if I add an alert at the bottom of the code (not anywhere else). What am I doing wrong?
<script type="text/javascript" language="javascript">
$(document).ready(function () {
$("#ana").submit(function () {
var lemma = $("#lexi").val();
var lex = new RegExp(".*<b>" + lemma + ".*");
jQuery.get('alfa.html', function (data) {
$("#apo").html(data.match(lex));
});
alert(lemma);
});
});
</script>
<div id="apo"></div>