I'm using jQuery to try and do some inline editing. So I use this code I made:
$(".info").click(function() {
var original = $(this).html();
var textarea = '<div><textarea name="comments" cols="60" rows="3">' + $(this).html() + '</textarea>';
var button = '<input type="button" value="Save" class="saveButton" /> OR <input type="button" value="Cancel" class="cancelButton" /></div>';
$(this).after(textarea+button).remove();
$('.cancelButton').click(function() {
$(this).parent().parent().html('<div class="info">' + original + '</div>');
$(this).parent().remove();
});
});
Now, everything works good. The only problem is that after I have clicked the cancel button and the code returns to it's original state (aka see first code I posted above), clicking it again DOES NOT DO ANYTHING.
It's as if the javascript is not noticing the click actions on the 'info' class anymore after doing it once.
Here's a gif I made to show the problem:
And what the code looks like after I click the cancel button and nothing happens:
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.6.4/jquery.min.js"></script> <div class="info">This is a test</div>
I'm using jQuery to try and do some inline editing. So I use this code I made: <script> var original; $(document).ready(function() { $(".info").click(function() { original = $(this).html();
var textarea = '<div><textarea name="comments" cols="60" rows="3">' + $(this).html() + '</textarea>'; var button = '<input type="button" value="Save" class="saveButton" /> OR <input type="button" value="Cancel" class="cancelButton" /></div>';
No that code you just posted doesn't work...unless I'm doing something wrong. Even putting that into a new document produces the same results I was having before.
The only problem is that after I have clicked the cancel button and the code returns to it's original state (aka see first code I posted above), clicking it again DOES NOT DO ANYTHING.
It's as if the javascript is not noticing the click actions on the 'info' class anymore after doing it once.
Here's a gif I made to show the problem:
I'm suppose to be able to click it over and over again to continue doing edits.
Alright so now it works for some reason maybe I was doing something wrong before! DOH!
Thanks.
Now after I have the textbox and buttons appear, how can I make the script get the text that's currently in the text box when the 'Save' button is clicked? I did something like this just to test it: