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

Time:09-08

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()));
});

CodePudding user response:

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>

  • Related