Hey all,
I have an object called Table that gets instantiated:
Code:
var tableReady = new Table($(this))
This Table in turn instantiates a header:
Code:
if(typeof header.attr('data-sorter') !== 'undefined') headers.push(new Header(header));
A method is attached to the Header object called attach() which simply passes in a string 'click':
Code:
var Header = function(header){
this.header = header;
this.addEventHandler(this.header, "click", attach("click"), true);
}
The addEventHandler() function is declared below:
Code:
function addEventHandler(oNode, evt, oFunc, bCaptures)
{
if (typeof(window.event) != "undefined")
oNode.attachEvent("on"+evt, oFunc);
else
oNode.addEventListener(evt, oFunc, bCaptures);
}
While the addEventHandler() function is called during Header instantiation, which in turn calls attach(), attach() is never executed unless there is a click event called on header object:
Code:
Header.prototype = {
attach: function(event){
var obj = this;
if(event == "click"){
obj.header.bind("click", function(e){
obj.children()[0].preventDefault();
return obj.calculate();
})
}
},
I call preventDefault() (I'm using the jquery library as well) to try to prevent the link from responding to a click by targeting obj.children()[0] which refgers to the nested link.
Unfortunately this doesn;t work. The link is still triggered anyway. How can I force the browser not to respond to the link in the above situation, preferably using an OOP solution?
Thanks for response.