code_junkie

How to JQuery DIV toggle more dynamic

Nov 13th, 2011
132
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.00 KB | None | 0 0
  1. $(function() {
  2. $("#commentLink").click(function()
  3. {
  4. $("#commentContainer").toggle();
  5. if ($("#commentContainer").is(":visible"))
  6. {
  7. $("#commentContainer").load($(this).attr("href"));
  8. } else
  9. {
  10. $("#commentContainer").html("Loading..."); //Or just leave it as is...
  11. }
  12. return false; //Prevent default action
  13. });
  14. });
  15.  
  16. <div id="SystemNews">
  17. <ul id="dc_news">
  18. <li>
  19. <a href="/Home/SystemNews/69" id="commentLink-0">Comments</a>
  20. <div id='commentContainer-0' style="display:none;"> Loading...</div>
  21. </div>
  22. </li>
  23. </ul>
  24. </div>
  25.  
  26. jQuery(function($){
  27. $("a[id^='commentLink-']").click(function(){
  28. match = this.id.match(/commentLink-(d+)/);
  29. container = $("div#commentContainer-"+match[1])
  30. container.toggle();
  31. if (container.is(":visible")) {
  32. container.load($(this).attr("href"));
  33. } else {
  34. container.html("Loading...");
  35. }
  36. return false; //Prevent default action
  37. });
  38. });
Add Comment
Please, Sign In to add comment