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'); 

fiddle


Comments

Popular posts from this blog

linux - Does gcc have any options to add version info in ELF binary file? -

android - send complex objects as post php java -

charts - What graph/dashboard product is facebook using in Dashboard: PUE & WUE -