Click here to Skip to main content
15,917,539 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
<div id="chatContainer">
    <div id="chatHeader" onclick="myfunction();">
    <img src="https://img/chaticon.png" style="vertical-align:middle;"/> Chat with us

    </div>
    <div id="chatBody">
    <div  id="Openhours">
        <iframe id="chatframe" src="https://www.chatmepage/Saleschat/">
        </iframe>
    </div> 
    <div id="Closedhours">            
        Sales hours are closed please <a target="_parent" href="https://www.xyz.com/contact">  Contact  </a> our Agents                       
    </div>
</div>
</div>


What I have tried:

onclick of the button I am appending the div, but I need to create the div onload of the page.


<!DOCTYPE html>


#chtping
{
vertical-align:middle;

}

#myForm
{
position: fixed;
background-color: #fff;
bottom: 0;
right:calc(50% - 200px);
color: #fff;
z-index: 10;
font-size: 18px;
overflow:hidden;
font-weight: bold;
background-color: #00a9e0;
border-radius: 5px;
border-radius: 5px 5px 0px 0px;
}
#chatbody
{
color: rgb(0, 0, 0);
font-weight: normal;
font-size: 13px;
height: 455px;
padding: 10px;
border-right-width: 1px;
border-right-style: solid;
border-right-color: rgb(204, 204, 204);
border-left-width: 1px;
border-left-style: solid;
border-left-color: rgb(204, 204, 204);
display:none;
background-color: white;
}
#myframe
{
width:100%;
height:100%;
Position:fixed;
margin-left:5px;
border:0;
}




Click the button to create a FORM and an INPUT element.



Try it




function myFunction() {
var x = document.createElement("div");
x.setAttribute("id", "myForm");
document.body.appendChild(x);

var y = document.createElement("div");
y.setAttribute("id", "chatheader");
y.innerHTML="<img id='chtping' src='https://img/chaticon.png'/>chat with us";
var chtbdy=document.createElement("div");
chtbdy.setAttribute("id","chatbody");
document.getElementById("myForm").appendChild(y,chtbdy);
var openhrs=document.createElement("div");
openhrs.setAttribute("id","Openhours");
openhrs.innerHTML("<iframe id='myframe' src='https://www.chatmepage/Saleschat/'></iframe>");
var closehrs=document.createElement("div");
closehrs.setAttribute("id","Closehours");
closehrs.innerHTML=("Sales hours are closed please <a target='_parent' href='https://www.xyz.com/contact'> Contact </a> our Agent");
document.getElementById("chatbody").appendChild(openhrs,closehrs);

}</pre>
Posted
Updated 8-Feb-17 23:47pm

1 solution

check this out: onload Event[^]
 
Share this answer
 
Comments
DbTalwar 9-Feb-17 6:43am    
Thank you! it is working as expected. may i know how to create div's dynamically?
Thanks in advance.
Peter Leow 9-Feb-17 7:48am    
Isn't that created by the myFunction()? For more info, visit http://www.w3schools.com/jsref/met_document_createelement.asp
DbTalwar 9-Feb-17 8:11am    
yes, but it is not coming as expected like HTML markup that i have.
Peter Leow 9-Feb-17 8:18am    
Draw out the DOM structure of your div and its elements on paper, identify the parent child nodes, then start coding the nodes in HTML by taking reference from the link that I have provided.
DbTalwar 9-Feb-17 8:25am    
yes i will,Thank you!

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900