PDA

View Full Version : first-sibling



jsonx
13 Sep 2009, 11:22 AM
Hi, I try to select first sibling td's id on click.


Ext.onReady(function(){
Ext.select("table").on("click", function(e,t){
e.stopEvent();
Ext.get(t).first(); //jQuery: $(e.target).siblings("td:first")
});
});


<table>
<tr>
<td id="foo">alfa</td><td>beta</td>
</tr>
<tr>
<td id="bar">alfa</td><td>beta</td>
</tr>
</table>

any help would be appreciated.

Animal
13 Sep 2009, 10:10 PM
Ext.override(Ext.Element, {
siblings: function(s) {
var n = this.dom.parentNode, r, c, i, l, rl;
if(s) {
r = Ext.DomQuery.select('/' + s, n);
for (i = 0, rl = r.length; i < rl; i++) {
if (r[i] === this.dom) {
r.splice(i, 1);
return r;
}
}
} else {
r = [];
c = n.childNodes;
for (i = 0, rl = c.length; i < rl; i++) {
if (c[i] !== this.dom) {
r.push(c[i]);
}
}
return r;
}
}
});

jsonx
19 Sep 2009, 7:00 AM
Thanks Animal. I think such methods should be added to the Ext Core.

Animal
19 Sep 2009, 11:51 PM
Maybe. But there are several dozen ways to skin any cat. eg:



Ext.onReady(function(){
Ext.select("table").on("click", function(e,t){
e.stopEvent();
Ext.get(t).up('tr').first();
});
});