jQuery replace element and access that replaced element

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 = $(''); $(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/

以上就是jQuery replace element and access that replaced element的详细内容,更多请关注web前端其它相关文章!

赞(0) 打赏
未经允许不得转载:web前端首页 » jQuery 答疑

评论 抢沙发

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址

前端开发相关广告投放 更专业 更精准