append() function in jQuery -
i'd enable user double-click on li elements on webpage results in addition of li's text textarea below.
the user can double-click more 1 li item. every time happens, new item appended of list in textarea.
i have default text in textarea: "double click on movie name in accordion insert."
hence, following html code:
<!-- there list before have not included --> <div id="chosen"> <form action="process.php?stage=4" method="post"> <textarea name="g" row="5">double click on movie name in list above insert.</textarea> <input type="submit" /> </form> </div>
and jquery:
$(document).ready (function(){ $('li').bind('dblclick', function(){ //#accordion var text = $(this).html() + "; "; $("textarea").append(text); }); });
the code absolutely works under normal circumtances, stops working when click in textarea modify contents. why so? there way code work when have touched textarea's contents?
(2) on note, why doesn't following code work? tried before discovered append() method. has got $(this) scope?
$(document).ready (function(){ $('li').bind('dblclick', function(){ //#accordion var text = $(this).html() + "; "; $("textarea").html( function() { //.chosen var currenthtml = $(this).html(); // retrieve current html first currenthtml += text; return currenthtml; }); }); });
(3) also, how program functionality allows, if user has double-clicked li element include textarea, undo inclusion? there method allows me opposite of append()?
just answer question 2)
the html() function used or insert text html tags (example: <div></div>
); content of textarea not html. equivalent is:
$("textarea").val("hello world!");
for first question, i've made fiddle: http://jsfiddle.net/nhkwq/ , and works (tested in chrome 26), if click textarea. can try reproduce behavior fiddle?
ok you're right when editing, doesn't work anymore...
edit:: works val() function:
$(document).ready(function () { $('li').bind('dblclick', function () { //#accordion var text = $(this).html() + "; "; $("textarea").val($("textarea").val() + text); }); });
Comments
Post a Comment