StylesBuilder divStyle = divBuilder.style();
divStyle.trustedBackgroundColor("red");
divStyle.endStyle();
// Append a child select element to the div.
SelectBuilder selectBuilder = divBuilder.startSelect();
// Append three options to the select element.
for (int i = 0; i < 3; i++) {
OptionBuilder optionBuilder = selectBuilder.startOption();
optionBuilder.value("value" + i);
optionBuilder.text("Option " + i);
optionBuilder.endOption();
}
/*
* End the select and div elements. Note that ending the remaining elements
* before calling asElement() below is optional, but a good practice. If we
* did not call endOption() above, we would append each option element to
* the preceeding option element, which is not what we want.
*
* In general, you must pay close attention to ensure that you close
* elements correctly.
*/
selectBuilder.endSelect();
divBuilder.endDiv();
// Get the element out of the builder.
Element div = divBuilder.finish();