3

Say I have html part in my GWT application:

    <ul>
        <li id="tray-active"><a data-field="home">Homepage</a></li> <!-- Active page -->
        <li><a data-field="news">News</a></li>
        <li><a data-field="products">Products</a></li>
        <li><a data-field="sales">General Sales T&C</a></li>
        <li><a data-field="job">Job Opportunities</a></li>
    </ul>

And I am able to get the AnchorElement, say for the HomePage:

@Inject @DataField Anchor home;

How can I get the List li element?

Is it: home.getParent(); // which returns a widget ? Then cast it to a UListElement ? Is that it?

Update:

My main goal is to set the id of the li element to "tray-active", so when anchor item is clicked the "parent" li element is set to to "tray-active"

quarks
  • 33,478
  • 73
  • 290
  • 513

2 Answers2

6

Need not to cast any thing.

you can do this:

home.getParent().getElement().setId("tray-active");

API

Suresh Atta
  • 120,458
  • 37
  • 198
  • 307
2

This should give you the Element object you want :

anchor.getElement().getParentElement()

where anchor is your anchor element.

anchor.getElement() 

Gives you the Anchor's element and

anchor.getElement().getParentElement() ;

will give you the Element parent to the anchor which in your case should be the li Element

Now if you want to set an Attribute to this element such as id do this:

anchor.getElement().getParentElement().setAttribute("id", "li_id") ;
Shourjya
  • 51
  • 8