You could create a wrapper method to handle this extra logic for you.
Something like (untested)...

Element.implement({
    getSomething: function(tag, something) {
        var el = this.getElement(tag);
        return el ? el.get(something) : null;
    }
});

var href = this.getSomething('a', 'href');

~Philip


On Wed, Oct 3, 2012 at 7:45 AM, Dimitar Christoff <christ...@gmail.com>wrote:

> you can be lazy and do:
>
> var prop = thisl.getElements('a').get('href').getLast();
>
> it's not the most performant.
>
> On 3 October 2012 11:39, Arian Stolwijk <stolwijk.ar...@gmail.com> wrote:
> > $() and .getElement() can return null if the element doesn't exist.
> > So if you're not sure the element exists, you'll have to check it indeed
> > with an if statement.
> >
> >
> > On Wed, Oct 3, 2012 at 12:36 PM, Hamburger <bilidi...@web.de> wrote:
> >>
> >> Hello,
> >> please let me have one more beginner question.
> >> With the following test I will get an error if the 'a' - element doesnt
> >> exsist.
> >> var test = this.getElement("a").get("href");
> >>
> >> What I would like to have is a 'null' or 'undefined'
> >>
> >> Do I have todo it realy like this:
> >> var test = this.getElement("a");
> >> if (test) {test=test.get("href");}
> >>
> >> or is there a shorter other way to do this.
> >
> >
>
>
>
> --
> Dimitar Christoff
>
> "JavaScript is to JAVA what hamster is to ham"
> @D_mitar - https://github.com/DimitarChristoff
>

Reply via email to