I am using jQuery's collapsible lists grouped and named #List01, #List02, #List03, etc.. My java script code captures clicks on list elements and remembers list item's id for further processing. Each group has identically looking code so I was wondering how could I encapsulate it in one function.
Here is the code:
$(document).on('click', '#List01 li', function ()
{
var anchor = $(this).find('a');
sessionStorage.KenID = anchor.attr('id');
changePage();
});
$(document).on('click', '#List02 li', function ()
{
var anchor = $(this).find('a');
sessionStorage.KenID = anchor.attr('id');
changePage();
});
$(document).on('click', '#List03 li', function ()
{
var anchor = $(this).find('a');
sessionStorage.KenID = anchor.attr('id');
changePage();
});
Thanks for your ideas! Jacek