Why does not appear the title?


Actively learn JavaScript, write a function that every two seconds queries page to see if its elements with the class .content? And as soon as inserted in the beginning of the inscription and terminates the survey. Please tell me why it doesn't work? After all, correctly.

function check() {
 var element = $( '.content' );
 if( element.length ) { // if the element appeared
 $( 'body' ).prepend( '<h1 style="font-size: 200px;">Hooray!</h1>' );
 } else {
 setTimeout( check, 2000 );
July 2nd 19 at 13:32
2 answers
July 2nd 19 at 13:34
Two options -- either the element is, in principle, does not appear or function after its definition is not invoked anywhere. In this example, the checking works (except that you need to wait 5 seconds).
July 2nd 19 at 13:36
then you need a special magic
var element = $(document).find( '.content' );
but it would be better to generate an event when adding '.content' and in this event should trigger the necessary actions.
read here

Find more questions by tags jQuery