PDA

View Full Version : CompositeElement help, I know there is an easier way



walden
11 Jan 2007, 8:57 PM
I know there is an easier way to do this but I had spent a few hours trying to get this working like I wanted and this is the only way it worked.... kind of strange looking & I am sure it only fluke that it actually worked.


var els=getEls("#lotstable td.eid").elements;
for( var i = 0 ; i < els.length ; ++i ) {
getEl(els[i]).on("click",function(oEvent,oThis){
window.open("http://url.com/page?id="+oThis.dom.innerHTML, '_blank');
});
}

Idealy it would be a one liner like this



getEls("#lotstable td.eid").on("click",function(){window.open("http://url.com/page?id="+this.dom.innerHTML, '_blank');});


But I can't for the life of me get it to work. I have played around with as many combos of scope & override as I can think of but still no joy.

Thanks for the help

Animal
12 Jan 2007, 12:51 AM
It should, but the best thing would be to have ONE click handler on the table, and to examine the target element of the click, and if it has the required class, open the window.

You could step into the call and fnid out why it's not working!

jack.slocum
12 Jan 2007, 5:53 AM
In the current development version, this does work if you add true:


getEls("#lotstable td.eid", true).on("click",function(){window.open("http://url.com/page?id="+this.dom.innerHTML, '_blank');});

In the dev code I have local, it works without the true (no this.dom):


getEls("#lotstable td.eid").on("click",function(){window.open("http://url.com/page?id="+this.innerHTML, '_blank');});

I will be checking in the new version soon. Like animal said, you should probably be using delegation for this.