Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Text of first div equals to text of second div equals to html of third div on keyup

I am having three div with content editable option and I want that text of 1st div = text of 2nd div = html of 3rd div. I am able to do it in two lines of code but code is not working when I am trying to convert it into single line. Please take a look at my code.

// Working Code
$("#img1").keyup(function() {
  $("#dimg1").html($(this).text());
  $("#oimg1").text($(this).text());
});

// Not Working
$("#img1").keyup(function() {
  $("#dimg1").html($("#oimg1").text($(this).text()));
});

>Solution :

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

This works, friend. But it’s ugly.

$("#img1").keyup(function() {
 $("#dimg1").html($("#oimg1").text($("#img1").text()).text());
});
body {display:flex}
div {flex:1 1; height:90vh;border:solid 1px #693}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>

<div id="img1" contenteditable></div>
<div id="dimg1"></div>
<div id="oimg1"></div>
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading