Jquery with CSS txtarea Live Preview with Div Function -


function: when click button, alt value of added text area , show live preview div , id alt value. on code there problem, when click button inserted whole code , id remove div tag , show alt code in preview show desired div. please me! thanks

<script type="text/javascript" src="http://code.jquery.com/jquery-latest.js"></script> <script> $(document).ready(function() {     $('.image').click(function(e){         var tav    = $('#image_code').val(),             strpos = $('#image_code')[0].selectionstart;         front  = (tav).substring(0,strpos),               = (tav).substring(strpos,tav.length);          $('#image_code').val(front + '<div id=\"' + $(this).attr("alt") + '\"></div>' + back).trigger('keyup');     });     $('#image_code').keyup(function() {         $('#image_preview').html( $(this).val() );     }); }); </script>  <style> #one{ background-color: black; width: 50px; height: 50px; border-radius: 2px; } #two{ background-color: red; width: 50px; height: 50px; border-radius: 2px; } #three{ background-color: blue; width: 50px; height: 50px; border-radius: 2px; } </style>  <textarea id="image_code"></textarea> <div id="image_preview"></div> <button id="1" class="image" title="1" alt="one">1</button> <button id="2" class="image" title="2" alt="two">2</button> <button id="3" class="image" title="3" alt="three">3</button> 

this seems rather weird, best understand of question, hoping achieve?

$('.image').click(function(e){     $('#image_code').val($(this).attr("alt")).trigger('keyup'); }); $('#image_code').keyup(function() {     var tav    = $('#image_preview').html();     strpos = $('#image_code')[0].selectionstart;     front  = (tav).substring(0,strpos),       = (tav).substring(strpos,tav.length);      $('#image_preview').html(front + '<div id=\"' + $(this).val() + '\"></div>' + back); }); 

http://jsfiddle.net/u3aeg/


Comments

Popular posts from this blog

linux - xterm copying to CLIPBOARD using copy-selection causes automatic updating of CLIPBOARD upon mouse selection -

c++ - qgraphicsview horizontal scrolling always has a vertical delta -