Today there was such a problem: before that, the append which was quietly used append after moving a few lines of code, suddenly stopped working. I did not find the reasons and tried to first make a benchmark simple example:
test.html :

 <html> <head> <script src="js/jquery-1.7.2.min.js"></script> <script src="js/test.js"></script> </head> <body> <h2>Greetings</h2> <div class="container"> exist </div> </body> </html> 

test.js :


And even it does not work. Tell me, what exactly might be wrong in this example? I point out I do not understand what the hell happened.

  • It works the same . Check paths, file names. - Denis Khvorostin
  • @Khvorostin, there is a little differently executed and the div time to appear. - Oleg Arkhipov

1 answer 1

At the time of loading test.js .container does not exist yet =)

This is not counting the fact that it is customary to insert text using text ( .html(), .text() ) methods, but this is a trifle.

  • Exactly, thank you so much, I again forgot about this pitfall of JS, which I hate the most. Before that, append was in a $ .ajax callback, and, accordingly, it was given a bit of delay. Then I moved him outside, and there he stopped working)) thanks. About the second note: this is for example, in the program itself, I insert a picture. - Oleg Arkhipov
  • one
    @Construct in fact, the problem is not JS, but in your hopeless PHP's shock :) - Zowie
  • Again, I support (as in some question where they wrote array.length () :)) - Rules
  • @AlexWindHope, do not immediately judge me because I am engaged in PHP. But that is another story ... - Oleg Arkhipov
  • By the way, I also had such a problem. I did not decide. And now everything is done. Thank! - MrGons18