
Untitled
By: a guest on
Apr 28th, 2012 | syntax:
None | size: 1.19 KB | hits: 18 | expires: Never
Jquery: add code using .append and make it work in .each in jquery
<ul>
<li> <a href="#" alt="1"> User1 </a>
<li> <a href="#" alt="2"> User2 </a>
</ul>
<div id="chat_rooms">
<div id='pvt0' class='pvtroom' page='room.php?id=0'><span>Chating With Default</span>
Here Is chat words
</div>
</div>
$('ul li a').live("click",function(){
var uid = $(this).attr("alt");
var uname = $(this).text();
$("#chat_rooms").append("<div id='pvt"+uid+"' class='pvtroom' page='room.php?id="+uid+"'> <span> Chating With "+ uname`enter code here` +" </span> </div>");
});
$('.pvtroom').each(function(){
// my ajax request to room here
$(this).css("border","1px solid #f00");
});
function initChatRoom(room) {
// my ajax request to room here
room.css("border","1px solid #f00");
}
$('.pvtroom').each(function(){
initChatRoom($(this));
});
$('ul li a').live("click",function(){
var uid = $(this).attr("alt");
var uname = $(this).text();
var room =
$("<div/>", { id: 'pvt'+uid, 'class': 'pvtroom', page: 'room.php?id='+uid })
.append($("<span/>").text('Chatting With '+ uname));
$("#chat_rooms").append(room);
initChatRoom(room);
});