javascript - Clickable colour boxes to change chat bubble colour -
I have a chat application where a user can submit a message and the message appears in the chat bubble with orange background I have created 5 colored div boxes that I want to link to the background color of the chat bubble. I hope that users can click on one of the colorful divas and the messages below will be displayed in the chat bubble along with that background. How can I do this?
See link for illustration:
Code:
HTML:
& lt; / Ul & gt; & Lt; Div & gt; & Lt; Input type = "text" id = "typetextbox" /> & Lt; Button type = "submit" id = "submit" & gt; & Lt; / Button & gt; & Lt; / Div & gt; & Lt; Div & gt; & Lt; Img src = "images / brown-block pages" id = "brown" /> gt; & Lt; / Div & gt; & Lt; Div & gt; & Lt; Img src = "images / blue-block pages" id = "blue" /> gt; & Lt; / Div & gt; & Lt; Div & gt; & Lt; Img src = "images / red-block" id = "red" /> gt; & Gt; / Div & gt; & Lt; Div & gt; & Lt; Img src = "images / green-block pages" id = "green" /> gt; & Gt; / Div & gt; & Lt; Div & gt; & Lt; Img src = "images / orange-block pages" id = "orange" /> & Lt; / Div & gt; java javasCRIPT: $ ('# typetextbox'). Keypress (function (e) {if (e.key.code == 13) $ ('# submit'). Click ();}); Val (); If (message.replace (/ / g, '')) {var posts = makeNewPosition (); Var == (' CSS:
li {height: auto, width: auto; Background: # E99D41; Status: Completed; Background opacity: 50%; Font-family: helvetica, non-serif, color: #fff; #blue {condition: full; Top: 88%; Left: 25%;} Make # brown, # red, # green, and # organs similar to #blue.
I hope that all this makes sense, and I'm sure this is a very simple thing, but I really appreciate the help!
<
var selected current = Color = undefined; $ ('.colorPicker & gt; div'). ('Click', function (e) {currentSelectedColor = $ (e.currentTarget) .attr ('class'); $ ('#tepetextbox') CSS ('background color', currentSelectedColor).}); $ ('# Submit') ('Click', function) {var msg = $ .trim ($ ('# typetextbox'). Val ()); if (msg == '') {return;} $ ('& lt; li / & AppendTo ('# messagebox') (AppendTo ("$ {": " );}); li {padding-bottom: 3px; List-style: none; } #message box & gt; Le & gt; Div {height: auto; Width: Auto; Font-family: helvetica, sans-serif; Display: Inline-Block} .colorPicker & gt; Div {width: 10px; Height: 10px; Display: inline-block} .red {background color: red; } .Green {background color: green; } .blue {background color: blue; } & lt; Script src = "https://ajax.googleapis.com/ajax/libs/JQuery/1.1.1/jquery.min.js" & gt; & Lt; / Script & gt; & Lt; Ul id = 'message box' & gt; & Lt; / Ul & gt; & Lt; Div class = 'color picker' & gt; & Lt; Div squared = 'red' & gt; & Lt; / Div & gt; & Lt; Div square = 'green' & gt; & Lt; / Div & gt; & Lt; Div class = 'blue' & gt; & Lt; / Div & gt; & Lt; / Div & gt; & Lt; Input type = "text" id = "typetextbox" /> & Lt; Button type = "button" id = "submit" & gt; Submit & lt; / Button & gt;
Comments
Post a Comment