I am creating some <div>
elements for my chat box application.
The following is the HTML part, in which on clicking a button the <div>
elements are created.
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<html>
<head>
<link rel="stylesheet" type="text/css" href="../chat/style.css"/>
</head>
<body>
<h1>Jquery div example</h1>
<button><i>click to create div</i></button>
</body>
</html>
The creation of <div>
elements seems OK. But I am unable to do anything on the created box.
This is the JQuery code for creating the div
:
$(document).ready(function(){
var chat_box_title = 'jaya chandra';
$("button").click(function(){
$('<div/>')
.attr({id:'chat_box_'+chat_box_title})
.addClass('chat_box')
.html('<div class="chat_head">jaya chandra<span class="chat_close"><a class="chat_close" href="javascript:void(0)" onclick="javascript:closeChatBox(\''+chat_box_title+'\')">X</a></span></div><div class="chat_wrapper"><div class="chat_body"></div><div class="chat_footer"><textarea rows="4" placeholder="Your message here..." class="chat_input"></textarea></div></div>')
.appendTo('body');
});
});
When the class .chat_head
is clicked then the .chat_wrapper
has to toggle.
I am trying to bind the click function using the following code..
$('body').on('click','div.chat_head>div.chat_wrapper',function(){
//$('.chat_wrapper').slideToggle('slow');
console.log('clicked');
});
I have tried all of my ideas for it, but I am unable to solve the problem.