javascript - What should I add here if the content of tags are changed then it should be reflect in text box -


when click me button clicked text of tag change. want implement if the span text changed similar span if inserted in div tag should change. link fiddle link

document.queryselector('.selectable-icons').addeventlistener('click', function(e) {         document.queryselector('[contenteditable]').appendchild(e.target.clonenode(true));      });    document.getelementbyid("clickme").onclick = function () { document.getelementsbyclassname('label')[0].innerhtml = 'new text';   };  document.queryselector('div').addeventlistener('keydown', function(event) {      // check backspace      if (event.which == 8) {          s = window.getselection();          r = s.getrangeat(0)          el = r.startcontainer.parentelement          // check if current element .label          if (el.classlist.contains('label')) {              // check if @ end of .label element              if (r.startoffset == r.endoffset && r.endoffset == el.textcontent.length) {                  // prevent default delete behavior                  event.preventdefault();                  if (el.classlist.contains('highlight')) {                      // remove element                      el.remove();                  } else {                      el.classlist.add('highlight');                  }                  return;              }          }      }      event.target.queryselectorall('span.label.highlight').foreach(function(el) { el.classlist.remove('highlight');})  });
[contenteditable] {    border: 1px solid #000;    margin: 0.4em 0;    line-height: 1.4em;    -webkit-appearance: textfield;    appearance: textfield;  }    img {    vertical-align: top;    max-height: 1.4em;    max-width: 1.4em;  }    .selectable-icons img {    cursor: pointer;  }    span.label.highlight {    background: #e1ecf4;    border: 1px dotted #39739d;  }    span.label {    background: #e1ecf4;    border: 1px dotted #39739d;  }
<p>just click on icon add it.</p>    <div class="custom-input">    <div class="selectable-icons">      <span class="label"> 1 </span>       <span class="label">i  2</span>         <span class="label">i  3</span>      </div>    <div contenteditable="true">      can type here. <span class="label"> 1 </span>  add icon.    </div>  </div><input id="clickme" type="button" value="clickme"   />

note : please dont give suggestion adding event clickme button. need when span text changes.the button reference. should event on change of span text. if tag removed , still added in text box there should tooltip saying missing. great if solution using meteor js blaze react js.


Comments

Popular posts from this blog

PHP and MySQL WP -

android - InAppBilling registering BroadcastReceiver in AndroidManifest -

go - golang pprof for c library code -