OK, I'm just getting to grips with jQuery and have a little issue.
I have a link that will change the contents of a <div> with a textarea
<a href="#" class="edit">Edit</a>
On click I want the save link to change the contents of the textarea in the original <div> heres the code I have for this
$(function(){
var content = $('.edit').text();
$('.edit').click(function(){
$('.content').html('<textarea class="text">' + content + '</textarea>');
$('.text').focus();
$(this).removeClass('edit').addClass('save').text('Save');
}
$('.save').live('click', function(){
$('.content').html($('.text').val());
$(this).removeClass('save').addClass('edit').text('Edit');
// Ajax code to save new content
});
});
My problem is when I click the Edit button because I add the class save it also executes the .save click function. How can make sure the .save function is only executed when I click the save function.