Reputation: 8608
Which way I can get GWT Elements by it's attribute ? I would like to get all of Elements by giving specific attribute and attribute-value.
<input type = "text" class = "get-TextBox" nature = "price"/>
<input type = "text" class = "get-TextBox" nature = "address"/>
<input type = "text" class = "get-TextBox" nature = "price"/>
above snipet , I want to get input elements by "nature" attribute and containing attribute-values of "price".
At my actual problem ,they are created by dynamic and not in same panel.Many Elements these having "nature" attribute and "price" attribute value. So , I am using DOM Handler for them.
Eg: JQuery (get element by attribute) , it is my main point to get.
But please don't suggest to ( iterate and check it's attribute ) . I am finding the easiest way to get it.
I would really appreciate your suggestions !
Upvotes: 2
Views: 3522
Reputation: 3832
You can use this code:
NodeList<Element> elements = Document.get().getElementsByTagName("input");
to get all of your inputs. Next step should be to iterate over the list and check the attributes with:
for (int i = 0; i < elements.getLength(); i++) {
if (elements.getItem(i).getAttribute("nature").equals("price")) {
// found it
}
}
a better way would be to use the attribute id instead of nature. In this case you get the element with:
Document.get().getElementById("price")
Alternative you can use Errai where you can bind your widgets to native HTML.
Upvotes: 4