开发者

Problem with jquery appendTo function

开发者 https://www.devze.com 2023-02-20 03:22 出处:网络
I have several textareas on my page and I use jquery focus function to clear the textarea when someone clicks it. Here is the code:

I have several textareas on my page and I use jquery focus function to clear the textarea when someone clicks it. Here is the code:

$("textarea.text").focus(function() {
    if( $(this).attr("has_desc") == "false" ) {
        $(this).val("");
        $(this).attr("has_desc", "true");
    }
});

The user has the abilit开发者_如何转开发y to dynamically add new textareas and I use appendTo function to add new one. The problem is that the above code doesn't work for the appended textareas! The HTML code is exactly the same as for the forms that aren't added dynamically! Can anyone please tell what is the problem?


.focus will not work for dynamically created elements. You could use .live('focus', function() ...

0

精彩评论

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