Similar to this : Event binding on dynamically created elements?
but I'm not adding an element dynamically only a class to an element using .addClass.
Basic html:
<div id="WebPartWPQ6_ChromeTitle">
<a accesskey="W" href="/siteurl" >
<span>Access </span></a></div>
Function:
(function($){
$.fn.sharePop = function(){
if(typeof OpenPopUpPage == 'function'){
return this.each(function(i){
if($(this).attr('href') != null){
$(this).click(function(e){
e.preventDefault();
OpenPopUpPage($(this).attr('href'));
});
}
});
}
else{
return false;
}
};
})(jQuery);
$(document).ready(function(){
$('.dialog-pop').sharePop();
});
To add class:
$( document ).ready(function() {
$( "#WebPartWPQ6_ChromeTitle a" ).addClass( "dialog-pop" );
});
The class gets added fine. But my assumption is it isn't there when the event gets attached to the element - and this line needs to change:
$(this).click(function(e){
I tried this:
$(this).on('click', '.dialog-pop', function(e){
But no luck.