I found another method that never messes with the contents of a text field. I like it, so I donโt have any special conditions that prevent the user from sending content that is only placeholder. The entry here is here , but I added the onclick method so that the label is clicked - without this, the user must click either below <label> or to the side of it. This works great with TinyMCE 4.
style
.tinyMCEPlaceholder { top: 45px; left: 9px; z-index: 1; color: #bbbbbb; position: absolute; cursor:text; }
HTML
<div id="holder"> <label for="tinymce" onclick="tinymce.execCommand('mceFocus',false,'area_id');">Type your article</label> <textarea id="comments" id="area_id" class="tinymce" name="comments" cols="40" rows="10"></textarea> </div> <div id="holder"> <label for="tinymce" onclick="tinymce.get('area_id').fire('focus',{},false);">Type your article</label> <textarea id="comments" id="area_id" class="tinymce" name="comments" cols="40" rows="10"></textarea> </div>
TinyMCE setup
// setup setup : function(ed) { /* toggle all labels that have the attr 'tinymce' */ ed.on('init', function() { if(ed.getContent() != '') { $('label[for="tinymce"]').hide(); } $(ed.getDoc()).contents().find('body').focus(function(){ $('label[for="tinymce"]').hide(); }); $(ed.getDoc()).contents().find('body').blur(function(){ if(ed.getContent() == '') { $('label[for="tinymce"]').show(); } }); }); },
source share