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() ...
精彩评论