jquery - How do I pass specific .on selector into function -
i have 2 versions of same code. first version works great not newly loaded content.
// fancy ajax loading , url rewriting when link clicked var linkbutton = $(".jshistory a"); linkbutton.on("click", function() { // if link selected nothing if($(this).parent().hasclass("selected")) { return false; // else load new content , update url } else { linky = $(this).attr("href"); history.pushstate(null, null, linky); showactivelink(); loadcontent(linky); return false; } });
in second version need relate specific linkbutton clicked , think work. i'm struggling pass selector through though.
// fancy ajax loading , url rewriting when link clicked var linkbutton = $(".jshistory a"); $(document).on({ click: function() { if link selected nothing if($(this).parent().hasclass("selected")) { return false; // else load new content , update url } else { linky = $(this).attr("href"); history.pushstate(null, null, linky); showactivelink(); loadcontent(linky); return false; } } }, linkbutton);
does know how achieve , if close think getting right? time.
it seems on()
accepts string delegated event handlers, , not jquery object, have this:
$(document).on({ click: function() { if( !$(this).parent().hasclass("selected") ) { var linky = $(this).attr("href"); history.pushstate(null, null, linky); showactivelink(); loadcontent(linky); } return false; } }, '.jshistory a');
Comments
Post a Comment