Reputation: 182
I need to create a span element inside div as soon as user starts typing in the div . I have set the contenteditable property of div as true but due to this the entered text is becoming part of the div and not the span I tried using spanelement.focus() method but it did not solved my problem .
This is my sample code snippet :
Element div = DOM.createDiv();
div.setClassName("intelliTextField");
div.setId("intelliTextField");
div.setAttribute("contenteditable", "true");
SpanElement span =div.appendChild(Document.get().createSpanElement());
initialSpan.setAttribute("contenteditable", "true");
i am appending this span element to div as soon as user starts typing in the div.But the entered text is becoming part of the div and not the span.
Any Help ?
Upvotes: 1
Views: 1829
Reputation: 1151
Is that what you mean?
Element div = DOM.createDiv();
div.setClassName("intelliTextField");
div.setId("intelliTextField");
div.setAttribute("contenteditable", "true");
Element spanElement = DOM.createSpan();
SpanElement mySpanElement = SpanElement.as(spanElement )
//do some job on SpanElement
DOM.appendChild(div, mySpanElement);
Of course you can omit creating SpanElement object and put directly spanElement into div via appendChild
Upvotes: 2