Fading in a div

Fading in a div

Hey again,


I have a problem and I just cannot figure out what is wrong. I want to show news on a page and to fade them in. I am using jQuery AJAX to pull out the news from a MySQL database. Here is the code (I will explain what the exact problem is in the code):

showNews.php - the relevant part
  1. $row = mysql_fetch_assoc($result);

  2. while ($row = mysql_fetch_array($result)) {
  3. echo '<div class="news"><div class="t"><div class="b"><div class="l"><div class="r"><div class="bl"><div class="br"><div class="tl"><div class="tr">
  4. <h2>' . $row['Title'] . '</h2>' . $row['Time'] . '<p>' . $row['Manchet'] . '</p><br />
  5. <a class="noDecoration" href="#" >&raquo; Read more...</a><br /><br /></div></div></div></div></div></div></div></div></div><br />';
  6. }

The output is as intended.


news.js - imported on index.php where I want to show the news
  1. $(function() {
  2. function fadeInNews() {
  3. console.log("inside fadeInNews function"); // This is sucessfully displayed in the console
  4. //$('#mainContent div.news').hide().fadeIn(5000); // When not commented out, this does not work
  5.                 // The tests below all output 0, so apparently the problem is finding the divs, which I do not understand since they do appear on the page like <div class="news">text</div>
  6. console.log($('#mainContent div.news').length);
  7. console.log($('div.news').length);
  8. console.log($('.news').length);
  9. }
  10. function displayNews(startNumber) {
  11. $.ajax({
  12. url: 'php/showNews.php',
  13. type: 'POST',
  14. data: 'num=' + startNumber, // Don't mind this; it is for coding paging
  15. success: function(result) {
  16. console.log(result); // The result is tested to be correct (even though only 2 out of 3 news show - but I will deal with that later)
  17. $('#mainContent').html(result, fadeInNews()); // The news do in fact show, but they do not fade in
  18. }
  19. });
  20. }
  21. displayNews(0);
  22. });
index.php contains a <div id="mainContent"></div>.

So, to sum up, selecting the news classes in the fadeInNews function does not work for me. Can anyone see what I did wrong?

Thanks a lot.