JSFiddle - React, Tailwind, and code Playground

by fragmentedreality

HTML

<input type="button" onclick="javascript: create_div();" value="create"/>
<div id="div-area"></div>

CSS

.chatdiv {
    background: grey;
    
}

JavaScript

function create_div() {
    $('#div-area').append('<div class="chatdiv">new chat</div>');
}
$(document).ready(function() {
    $('#div-area div.chatdiv').live('click', function(e, o) {
        $(e.target).css('background', 'red');
    });
    $(document).on('click', '#div-area div.chatdiv', function(event, data) {
        // select the element of interest via the event
        $(event.target).css('font-weight', 'bold');
        // select the element of interest directly
        $(this).css('color', '#ddd');        
    });
});