Skip to Main Content

Java SE (Java Platform, Standard Edition)

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

placeholder not working on the div tag <HTMLEditor>

sushmita.patilOct 23 2017 — edited Nov 2 2017

I would like to add some text when div is empty, I tried adding placeholder to the div, but it is not replacing the text when new text is being added.

HTML text:

<div  contenteditable="true" placeholder="{enter text here}"/>

</div>

div:empty:before {

  content:attr(placeholder);

  color:gray

}

Also tried using js to replace the text on click but not working as expected.

below is the javascript code:

function selectText( containerid ) {

    var node = document.getElementById( containerid );

    if ( window.getSelection ) {  

       var range = document.createRange();      

        range.selectNodeContents( node );

       window.getSelection().addRange( range );

    }

}

Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Nov 30 2017
Added on Oct 23 2017
1 comment
524 views