Note that there are some explanatory texts on larger screens.

plurals
  1. POshow borders and handles on textarea when highlighted
    primarykey
    data
    text
    <p>I have dynamically created textareas which are nested in a dynamcally created divs. the divs are draggabnle and the textareas are resizable using jquery.</p> <p>I want the border and drag/resize handles for any paticular div/textarea to only appear when the user clicks on that paticular textarea. I am assuming I would need to use the same onclick event that the draggable is using but I dont have the js knowledge for making the handles and border show up.</p> <p>any help greatly appreciated</p> <p>here is my code</p> <pre><code>&lt;!DOCTYPE html&gt; &lt;html&gt; &lt;meta charset="utf-8" /&gt; &lt;head&gt; &lt;style&gt; body{background-color:#ccc;} .dragbox{width:10px; height:10px;padding: 0.0em; margin:25px; border:0;cursor:move; z-index:2} .textarea1{ width: 300px; height: 300px; padding: 0.5em; z-index:3} #handle{ display: block; height: 16px; width: 100px; background-color: red; position: absolute; top:-15px; left:0px; font-size:10px; } #content { position:absolute; top:150px; left:0px; margin:auto; z-index:1; } &lt;/style&gt; &lt;link rel="stylesheet" href="http://code.jquery.com/ui/1.10.1/themes/base/jquery-ui.css" /&gt; &lt;script src = "http://js.nicedit.com/nicEdit-latest.js"&gt;&lt;/script&gt; &lt;script src="http://code.jquery.com/jquery-1.9.1.js"&gt;&lt;/script&gt; &lt;script src="http://code.jquery.com/ui/1.10.1/jquery-ui.js"&gt;&lt;/script&gt; &lt;script&gt; var i=0; var p=25; } function editor1(idf) { //var body = document.body; // The magic document.getElementById(idf).addEventListener ("dblclick", function (event) { var target = event.target; if (target.nodeName === "TEXTAREA") { var area = new nicEditor ({fullPanel : true}).panelInstance (target); area.addEvent ("blur", function () { this.removeInstance (target); }); } }, false); }; function NewTextArea(id) { id=id+i; var newdiv = document.createElement('div'); newdiv.setAttribute('id', id); newdiv.setAttribute('class', 'dragbox'); newdiv.setAttribute('iterate',i); newdiv.style.position = "relative"; newdiv.style.top = p; newdiv.style.left = p; newdiv.style.cursor='move'; newdiv.innerHTML = "&lt;div id='handle'&gt;Drag me into position&lt;/div&gt;&lt;/div&gt;&lt;br&gt;&lt;textarea id='"+i +"' onDblClick='editor1("+i+")' name='textarea["+i +"]' class='textarea1' style='position:absolute; top:0px;left:0px;overflow-y: auto;background-color:transparent;border: 2px dashed #000; '&gt;some text here&lt;/textarea&gt;"; newdiv.innerHTML=newdiv.innerHTML+"&lt;br&gt;&lt;input type='hidden' value='"+i+"' name='id["+i+"]'&gt;&lt;br&gt;&lt;input name='box_type["+i+"]' type='hidden' value='text'/&gt;"; newdiv.innerHTML=newdiv.innerHTML+"&lt;br&gt;&lt;input type='hidden' value='300' name='width["+i+"]' id='width"+i+"'&gt;&lt;br&gt;&lt;input type='hidden' value='300' name='height["+i+"]' id='height"+i+"'&gt;"; newdiv.innerHTML=newdiv.innerHTML+"&lt;br&gt;&lt;input type='hidden' value='0' name='left["+i+"]' id='left"+i+"'&gt;&lt;br&gt;&lt;input type='hidden' value='0' name='top["+i+"]' id='top"+i+"'&gt;"; document.getElementById("frmMain").appendChild(newdiv); $(function() { $("#"+i).resizable( { stop: function(event, ui) { var width = ui.size.width; var height = ui.size.height; // alert("width="+width+"height="+height); ValProportions(width,height,ui.element.context.id); } }); $( "#"+id ).draggable( { stop: function(event, ui) { Stoppos = $(this).position(); $("div#stop").text("STOP: \nLeft: "+ Stoppos.left + "\nTop: " + Stoppos.top); // alert("left="+Stoppos.left+"top="+Stoppos.top); ValPostion(Stoppos.left,Stoppos.top,$(this).attr('iterate')); } }); $("#"+i).draggable({handle:"#handle"}); }); function ValProportions(defaultwidth, defaultheight,id) { $('#width'+id).val(defaultwidth); $('#height'+id).val(defaultheight); } function ValPostion(defaultleft,defaulttop,id) { $('#left'+id).val(defaultleft); $('#top'+id).val(defaulttop); } i++; p=p+25; } &lt;/script&gt; &lt;/head&gt; &lt;body&gt; &lt;form id="frmMain" name="frmMain" enctype="multipart/form-data" action="dynamic_div5.php" method="post"&gt; &lt;input id="btn1" type="button" value="Add New textbox" onClick="NewTextArea('draggable');"/&gt; &lt;input type="submit" value="Save Page" &gt; &lt;/form&gt; &lt;/body&gt; &lt;/html&gt; </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload