I'm in progress to learn jQuery. I want to add a feature so when user clicks on a td with a specified class name, I want to change it into an select option. And with that selected value i want to update my db.
Until here its okay. I can change the td to an input however, I can't add an event on change event to that replaced element.
Here is what I have:
(function($) {
var _defaults = {
some : "defaults",
};
$.fn.changetoi = function(options) {
var _opts = $.extend({}, _defaults, options);
$(this).on('click', function() {
var replaced = $('<select name="status" class="changer"><option>Test</option></select>');
$(this).replaceWith(replaced);
});
$('.changer').on('change', function() { //here I'm try to access the changed element
var value = $(".changer option:selected").text();
//post the selected value
$.post("test.php", {
"value" : value
}, function(data) {
//whatever and
$(this).replaceWith(value);
});
});
};
$('.change').changetoi();
})(jQuery);
and here is the fiddle for table, test and such http://jsfiddle.net/HZvH8/4/