views:

117

answers:

1

Hi Guys,

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) {
}

});
+2  A: 

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');
thoughtcrimes