Struggling a little here with prototype = I've created this function
开发者_运维百科Event.observe(window, 'load', function() {
if ($$('#test li:first')!=null) {
$('test').down('li').down('a').update('Test');
}
});
Basically, it works on pages where #test li:first is found but on pages it isn't it returns
$("test").down("li") is undefined
I just wanted it to basically work only if it found the element otherwise not work ?
Edit: Solved
Event.observe(window, 'load', function() {
try {
if ($$('#test li:first')!=null) {
$('test').down('li').down('a').update('Test');
} }
catch(ex) {
}
});
That's not really solving it; you are just catching an error that is easily fixed.
Try this on for size:
$$('#test li:first-child').invoke('update', 'Test');
精彩评论