I'm creating an inline edit input['text'] snippet with jQuery.
the html will be like this :
<div id="inline">
<span class="item">Color</span>
</div>
I got stuck in here (here is my code) :
$('.item').each(function(){
$(this).click(function(){
$(this).hide();
$(this).parent().append(
'<form method="post" action="" id="inline_form">'+
'<input type="text" value="'+ $(this).html() +'"> <input type="Submit" value="update" />'+
' <a href="#" class="cancel">Cancel</a></form>'
);
});
});
I want to bind a click event to class '.cancel' that I've appended above , so when I click cancel, it will remove the form '#inline_form' and show back '.item'
I tried this
$('.cancel').each(function(){
$(this).click(function(){
$(this).parent('#inline').find('.item').show();
$(this).parent('#inline_form').remove();
});
});
But it didn't work. How do I select '.cancel' so I can put a click event on it ???