domchange : function(instance){
$("#server-players-list table thead th").click(function() {
var rowIndex = $(this).index();
alert("Index of row: " + rowIndex);
});
}
$("xyz").on("click.myprefix")
.domchange : function(instance){
if(window.location.href.match(/correct\/page\/url/)){
$("#server-players-list table thead th").off(".myprefix").on("click.myprefix", function() {
var rowIndex = $(this).index();
alert("Index of row: " + rowIndex);
});
}
}
BrainFooLong wrote:Domchange is the right place, but you need to do some checks.
First check if you are on the right page, using window.location.href.match for example.
Secondly, you should prefix your click event by using that for example$("xyz").on("click.myprefix")
.
At third, unbind any of your previously attached click events everytime the domchange triggers, that prevent you from multiple bindings.
All in all could be something like this
domchange : function(instance){
if(window.location.href.match(/correct\/page\/url/)){
$("#server-players-list table thead th").off(".myprefix").on("click.myprefix", function() {
var rowIndex = $(this).index();
alert("Index of row: " + rowIndex);
});
}
}
var mutationHandler = function(mutations){
// onchange code
};
var observer = null;
if(typeof WebKitMutationObserver != "undefined"){
observer = new WebKitMutationObserver(mutationHandler);
}else if(typeof MutationObserver != "undefined"){
observer = new MutationObserver(mutationHandler);
}
observer.observe(document.body, { childList: true , subtree : true});