javascript - How to trigger AJAX requst only onmouseover -
i have below script shows values search page onmouseover
.
<script type="text/javascript"> function preview(val) { $.ajax({ type: "post", url: "search.php", data:'id='+val, success: function(data){ $(".ress").html(data); } }); } </script>
html :
<div class="cvsearchresult" onmouseover="preview('1')">
search :
<?php echo $_post['id']; ?>
output class .ress :
1
however want hide output onmouseout
well. how can this? mean trigger ajax mouse hover , hide if not hover.
<div class="cvsearchresult" onmouseover="preview('1')" onmouseout="hide()"> <script> function hide() { $(".ress").html(''); } </script>
you adding event handler when user move mouse away element trigger hide function.
the hude function grab result dom element(which can contain selected results previous calls) , set html empty string.
that way when move away mouse div element cleared.
Comments
Post a Comment