javascript - Get a variable immediately after typing -


i have code

<span></span> 

and

<div> variable number </div> 

and

<script>  $(document).ready(function(){   var x = $('div').html();   $('span').html(x) });  </script> 

i need every time change div value, span reflects changes of div

for example.

if type 1 in div, span should show me number 1

if type 3283 in div, span should show me number 3283

but code - need create

$("div").click(function(){        var x = $('div').html();       $('span').html(x)  }); 

i not want use .click(function) . in need function run automatically

after answer use code

http://jsfiddle.net/danin_na/uuo8yht1/3/

but doesn't work . whats problem ?

this simple. if add contenteditable attribute div, can use keyup event:

var div = $('div'),      span = $('span');    span.html(div.html());    div.on('keyup', function() {      span.html(div.html());  });
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>  <span></span>  <div contenteditable="true"> variable number </div>


Comments

Popular posts from this blog

IF statement in MySQL trigger -

c++ - What does MSC in "// appease MSC" comments mean? -

javascript - Blogger related post gadget image Resize s72-c [ Need Expert Help ] -