jquery - Get the event invoking page -


is there way in jquery name of document/page has invoked event?

below on change event common 2 pages , elements in both documents/pages have class new_featured_image

$( document ).on( "change", ".new_featured_image", function() {         // code document/page name  }); 

there's no need use jquery, can read

window.location.href 

and give address of page (should enough identify page).

anyway, it's not clean way achieve goal. it's preferrable add class "body" tag depending on page ("pageone" , "pagetwo") , use class either identify page, like:

 $( document ).on( "change", ".new_featured_image", function() {        if(body.hasclass("pageone")) {...}       else {...}   }); 

or add 2 different listeners:

 $( document ).on( "change", "body.pageone .new_featured_image", function() { // code document/page name });  $( document ).on( "change", "body.pagetwo .new_featured_image", function() { // code  

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 -