Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on Apr 28th, 2012  |  syntax: None  |  size: 1.19 KB  |  hits: 18  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. Jquery: add code using .append and make it work in .each in jquery
  2. <ul>
  3.    <li> <a href="#" alt="1"> User1 </a>
  4.    <li> <a href="#" alt="2"> User2 </a>
  5. </ul>
  6.  
  7. <div id="chat_rooms">
  8.  
  9.   <div id='pvt0' class='pvtroom' page='room.php?id=0'><span>Chating With Default</span>
  10.       Here Is chat words
  11.  </div>
  12.  
  13. </div>
  14.        
  15. $('ul li a').live("click",function(){
  16.        var uid = $(this).attr("alt");
  17.        var uname = $(this).text();
  18.        $("#chat_rooms").append("<div id='pvt"+uid+"' class='pvtroom' page='room.php?id="+uid+"'> <span> Chating With "+ uname`enter code here` +" </span> </div>");
  19. });
  20.        
  21. $('.pvtroom').each(function(){
  22.          // my ajax request to room here
  23.          $(this).css("border","1px solid #f00");
  24.   });
  25.        
  26. function initChatRoom(room) {
  27.   // my ajax request to room here
  28.   room.css("border","1px solid #f00");
  29. }
  30.  
  31. $('.pvtroom').each(function(){
  32.   initChatRoom($(this));
  33. });
  34.        
  35. $('ul li a').live("click",function(){
  36.   var uid = $(this).attr("alt");
  37.   var uname = $(this).text();
  38.   var room =
  39.     $("<div/>", { id: 'pvt'+uid, 'class': 'pvtroom', page: 'room.php?id='+uid })
  40.     .append($("<span/>").text('Chatting With '+ uname));
  41.   $("#chat_rooms").append(room);
  42.   initChatRoom(room);
  43. });