onavailable

How to do something when available with jQuery?

限于喜欢 提交于 2019-12-11 15:43:51
问题 I've loaded a <textarea> with javascript, and need to focus on it as soon as it's available. The live() in jQuery must specify a "type" which doesn't exists in my case. I need to do something like below: $('#target').onAvailable($('#target').focus()); How to implement this with jQuery? 回答1: Use a callback: $("...").load("/something/to/load.html", function() { $("textarea", this).focus(); }); 来源: https://stackoverflow.com/questions/1387464/how-to-do-something-when-available-with-jquery

Is there a onAvailable() function in jQuery?

主宰稳场 提交于 2019-12-04 05:56:55
问题 After inserting new html to DOM,I need to add some listeners to it. But the new elements are not available at once. My code: $('#loader').clone().removeAttr('id').load("Views/chatBox.html").appendTo('body'); $('#chat') .focus(function() { $(this).addClass('jV'); }) .blur(function() { $('#chat').removeClass('jV'); }); Which is not working . Using live() still not working: $('#chat').live('focus',function() { $('#chat').addClass('jV'); }) .live('blur',function() { $('#chat').removeClass('jV');

Is there a onAvailable() function in jQuery?

泄露秘密 提交于 2019-12-02 11:32:50
After inserting new html to DOM,I need to add some listeners to it. But the new elements are not available at once. My code: $('#loader').clone().removeAttr('id').load("Views/chatBox.html").appendTo('body'); $('#chat') .focus(function() { $(this).addClass('jV'); }) .blur(function() { $('#chat').removeClass('jV'); }); Which is not working . Using live() still not working: $('#chat').live('focus',function() { $('#chat').addClass('jV'); }) .live('blur',function() { $('#chat').removeClass('jV'); }); If #chat is in the chatBox.html that you are loading then you can take advantage of the callback