xxxxxxxxxx
1
<div class="container my-5">
2
3
<!-- Section: Introduction -->
4
<section class="">
5
6
<p>
7
Detailed documentation and more examples you can find in our
8
<a href="https://mdbootstrap.com/docs/standard/extended/textarea/" target="_blank"><strong>Textarea Docs</strong></a>.
9
</p>
10
11
<hr class="mt-5">
12
13
<p>Built with <a target="_blank" href="https://mdbootstrap.com/">Material Design for Bootstrap</a> - <strong>free</strong> and powerful Bootstrap UI KIT</p>
14
15
<a class="btn btn-danger me-2" href="https://mdbootstrap.com/" target="_blank" role="button">Download MDB UI KIT</a>
16
<a class="btn btn-dark me-2 px-3" target="_blank" href="https://github.com/mdbootstrap/mdb-ui-kit" role="button"><i class="fab fa-github"></i></a>
17
18
<hr class="mb-5"/>
19
20
</section>
21
<!-- Section: Introduction -->
22
</div>
23
24
<div class="container my-4">
25
26
<p class="font-weight-bold">Bootstrap message is a component dedicated for text-based communication between two or
27
more users in real time.</p>
28
29
<hr class="my-5">
30
31
<div class="border border-light p-5">
32
33
<ul id="some-ul" class="list-unstyled">
34
<li class="d-flex justify-content-start mb-4">
35
<img src="https://mdbootstrap.com/img/Photos/Avatars/avatar-7.jpg" alt="avatar" class="avatar rounded-circle mr-2 ml-lg-3 ml-0 z-depth-1">
36
<div class="chat-body white p-3 ml-2 z-depth-1">
37
<div class="header">
38
<strong class="primary-font">Brad Pitt</strong>
39
<small class="pull-right text-muted"><i class="fa fa-clock-o"></i> 12 mins ago</small>
40
</div>
41
<hr class="w-100">
42
<p class="mb-0">
43
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut
44
labore et dolore magna aliqua.
45
</p>
46
</div>
47
</li>
48
<li class="d-flex justify-content-end mb-4">
49
<div class="chat-body white p-3 z-depth-1">
50
<div class="header">
51
<strong class="primary-font">Lara Croft</strong>
52
<small class="pull-right text-muted"><i class="fa fa-clock-o"></i> 13 mins ago</small>
53
</div>
54
<hr class="w-100">
55
<p class="mb-0">
56
Sed ut perspiciatis unde omnis iste natus error sit voluptatem accusantium doloremque laudantium.
57
</p>
58
</div>
59
<img src="https://mdbootstrap.com/img/Photos/Avatars/avatar-5.jpg" alt="avatar" class="avatar rounded-circle mr-0 ml-3 z-depth-1">
60
</li>
61
<li class="d-flex justify-content-start mb-4 pb-3">
62
<img src="https://mdbootstrap.com/img/Photos/Avatars/avatar-7.jpg" alt="avatar" class="avatar rounded-circle mr-2 ml-lg-3 ml-0 z-depth-1">
63
<div class="chat-body white p-3 ml-2 z-depth-1">
64
<div class="header">
65
<strong class="primary-font">Brad Pitt</strong>
66
<small class="pull-right text-muted"><i class="fa fa-clock-o"></i> 12 mins ago</small>
67
</div>
68
<hr class="w-100">
69
<p class="mb-0">
70
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut
71
labore et dolore magna aliqua.
72
</p>
73
</div>
74
</li>
75
<li id="give-me-msg" class="white">
76
<div class="form-group basic-textarea">
77
<textarea class="form-control pl-2 my-0" id="exampleFormControlTextarea2" rows="3" placeholder="Type your message here..."></textarea>
78
</div>
79
</li>
80
<button id="send-msg" type="button" class="btn btn-info btn-rounded btn-sm waves-effect waves-light float-right">Send</button>
81
</ul>
82
83
</div>
84
85
</div>
xxxxxxxxxx
1
.avatar {
2
width: 50px;
3
height: 50px;
4
}
xxxxxxxxxx
1
$('#send-msg').on('click', textAreaMessage);
2
const $textArea = $('#exampleFormControlTextarea2');
3
const yourSrcImg = 'https://mdbootstrap.com/img/Photos/Avatars/avatar-1.jpg';
4
const yourName = 'Pjoter';
5
6
function textAreaMessage() {
7
let $newLi = $('<li>');
8
let $newDiv = $('<div>');
9
let $textareaText = $textArea.text();
10
$newLi.addClass('d-flex justify-content-start mb-4 pb-3');
11
$newLi.prepend(
12
'<img src="' + yourSrcImg + '" alt="avatar" class="avatar rounded-circle mr-2 ml-lg-3 ml-0 z-depth-1">'
13
).append(
14
'<div class="chat-body white p-3 ml-2 z-depth-1"><div class="header"><strong class="primary-font">' +
15
yourName +
16
'</strong><small class="ml-3 pull-right text-muted"><i class="fa fa-clock-o"></i> 12 mins ago</small><hr class="w-100"><p class="mb-0">' +
17
$('#exampleFormControlTextarea2').val() +
18
'</p></div>'
19
);
20
$newLi.insertBefore('#give-me-msg');
21
22
$('#exampleFormControlTextarea2').val('');
23
}
24
25
$('#some-ul').on('keypress', '#exampleFormControlTextarea2', function (e) {
26
if (e.which === 13) {
27
textAreaMessage();
28
}
29
});
Console errors: 0