Call user defined function in jquery

I have user-defined function like below, i need to call it while click on search button and as well as by pressing enter button.

<input id="cnc-search" type="text" name="" class="cnc-inputloc" value=""/> // input box
<span class="quick-search" id="quickviewsearch"></span>// search icon

function myFun(){
alert('hi');
}

Tried like below is it correct way.

$(document).ready(funtion(){
	$("#quickviewsearch").on('click keypress', myFun);
	$('#cnc-search').keypress(function(e){
        if(e.which == 13){//Enter key pressed
            $('#quickviewsearch').click();
        }
    });

You might want to correct the typo in the word “function” on the first line of the JS

$(document).ready(funtion(){

I don’t know whether that will get the behaviour you want, but it can’t be helping. :slight_smile:

@chrisofarabia: Yeah, Corrected the typo, just to know is this better way programming wise.:slight_smile:
Anyhow the code is working.

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.