Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to assign attributes or functions to objects added after DOm ready with jquery
    primarykey
    data
    text
    <p>I am working in some personal project it is like the front-end of a chat. So i have my users and i have a JSON with the list of online and offline users. When the website firs load I also load plugins for custom scroll and make elements draggable with jquery ui. what i would like to know is if there is a way to make the new elements added to the body (chat windows) automatically be scrollable and have this custom scroll bar every time I add them. So far what I do es something like :</p> <pre><code>$(document).on("ready", functions); function functions() { $("#contacts-container").slimScroll({ height: '220', size: '10px', position: 'right', color: '#535a61', alwaysVisible: false, distance: '0', railVisible: true, railColor: '#222', railOpacity: 0.3, wheelStep: 10, disableFadeOut: false }); $(".messages-container").slimScroll({ height: '200', size: '10px', position: 'right', color: '#535a61', alwaysVisible: false, distance: '0', railVisible: true, railColor: '#222', railOpacity: 0.3, wheelStep: 10, disableFadeOut: false, start: "bottom" }); $("#online .user-name").on("click", checkUser); }; function checkUser(){ console.log("clicked"); var user = $(this).html(); $.getJSON("js/options.json", function(json){ var itemsLength = json.chat.OnlineContacts.length; for ( var i = 0; i &lt; itemsLength; i++) { var jsonUserName = json.chat.OnlineContacts[i].name; var jsonUserStatus = json.chat.OnlineContacts[i].status; var jsonUserAvatar = json.chat.OnlineContacts[i].picture; if(user == jsonUserName){ displayChatWindow(jsonUserName, jsonUserStatus, jsonUserAvatar); } }; }); } function displayChatWindow(user, status, avatar){ console.log(avatar); var template = _.template($("#windowTemplate").html(), {userName: user, userStatus: status, userAvatar: avatar}); $("body").prepend(template); $(".messages-container").slimScroll({ height: '200', size: '10px', position: 'right', color: '#535a61', alwaysVisible: false, distance: '0', railVisible: true, railColor: '#222', railOpacity: 0.3, wheelStep: 10, disableFadeOut: false, start: "bottom" }); $(".friend-window").draggable({handler: ".header"}); } </code></pre> <p>On the DisplayChatWindow I append the template wich is s div representing the chat window, but i also have to re add the slimScroll function and the draggabla function, but i would like them to automatically have it once i append it, I am learning Java Script so I don't know if using an object i can achieve this or if there is another way, basically what i have done here it the most i know how to do so far, i will appreciate if you guys can help me :) </p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload