jQuery on, add only one event listener -


i have event listener ul:

$('body').on('click.submenu', '.top-level', submenu); 

is there way ensure gets added once?

the reason being, need added when viewport @ "mobile" breakpoint, , when goes desktop mobile, there seems more 1 event listener.

var body = $("body");                             //store later use if(!(body.data("eventadded") === true)){            //test if event added     body.data("eventadded", true)                     //if not, set eventadded true         .on('click.submenu', '.top-level', submenu);  //and add event } 

Comments

Popular posts from this blog

javascript - Jquery show_hide, what to add in order to make the page scroll to the bottom of the hidden field once button is clicked -

javascript - Highcharts multi-color line -

javascript - Enter key does not work in search box -