Jquery Live Preview in Text Area with function -
i have here code when click div insert textarea , show preview. content inserted in textarea image doest show image live instead needs type character on textarea.
<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 + '<img src=\"' + $(this).attr("alt") + '\">' + back); }); $('#image_code').keyup(function() { $('#image_preview').html( $(this).val() ); }); }); </script> <textarea id="image_code"></textarea> <div id="image_preview"></div> <div id="1" class="image" title="1" alt="http://xxxx.jpg">1</div> <div id="2" class="image" title="2" alt="http://xxxx.jpg">2</div> <div id="3" class="image" title="3" alt="http://xxxx.jpg">3</div> <div id="4" class="image" title="4" alt="http://xxxx.jpg">4</div> <div id="5" class="image" title="5" alt="http://xxxx.jpg">5</div>
please me. lot!
if you're trying insert image inside textarea
i'm afraid can't: they're designed handle text (wysiwyg editors use trickery around this).
instead, use contenteditable
div, or try setting background image... image won't actual physical element within textarea.
Comments
Post a Comment