Jquery event to display element

I try to do all the window manipulations and then make them visible. Which works, but now I have a situation where I am trying to do this using a form that I want to focus on the first source when rendering it in a browser.

Something like: myForm.prependTo(myDiv).show().find('input:first').focus();

The problem is that the focus is called before the form has finished rendering, which causes a wonderful error . It is not possible to move focus to a control because it is invisible, not included, or a type that does not accept focus.

How do other web developers deal with a similar situation of manipulating elements off the screen and then make it visible? I want jQuery to have something like
myForm.prependTo(myDiv, function() { /* on render code here */ })

I know that one way to do this is to set a timeout, and when it fires, I focus on the input, but I feel that this is not the cleanest way to do something. I know iframe has an onload event, so I wonder if people usually draw their elements in some kind of hidden iframe and listen to the load event to find out when the element finished rendering? If you could give me an example of this?

+4
source share
2 answers
myForm.prependTo(myDiv).show(function(e){
    $(this).find('input:first').focus();
});​
+2
source

I know that I was 7 years late, but I had a similar problem that I solved by putting the material that was supposed to happen after rendering in a ready-made handler.

, , , .

. , .

$("#someSelector").empty(); restore();

, ready() ; - ....

$("#someSelector").empty().ready(function() { restore(); });

restore() , empty() RENDERS. , , ( , ).

, . , , . "jquery" "render" .

, , , , , - .

.

+1

All Articles