开发者

set value for current elements and dynamically added elements in jquery

开发者 https://www.devze.com 2023-02-25 09:35 出处:网络
I have the following code but it doesn\'t work $(\"body\").delegate(\"textarea\", \"ready\", function () {

I have the following code but it doesn't work

$("body").delegate("textarea", "ready", function () {
    $(this).val("custom value");
});

My intent is s开发者_如何学运维et that value for current elements on the dom and future textareas added dynamically to the page, is there a solution?


.ready is an event that occurs on the document, not when other elements are loaded. Unfortunately there is not a graceful solution to this either. The best suggestion I can make is that after each of your ajax requests complete, to select all textareas and set their values:

// maybe something similar to this.
$(document).ajaxSuccess(function() {
  $('textarea').val('custom value');
});
0

精彩评论

暂无评论...
验证码 换一张
取 消