Suraj Air
Suraj Air

Reputation: 2113

Creating a <div> at runtime

I want to know whether i can create <div> at runtime using JavaScript or any other method: when clicking a button on one <div> another <div> should appear, and both <div>s should lay above the html page below (i.e floating <div>s).

Upvotes: 1

Views: 2454

Answers (3)

manish
manish

Reputation: 1

 <html>
 <head>
 <script>
 var ans=document.createElement('div');

 ans.setAttribute('id','kk');

 ans.setAttribute('name','jj');

 ans.setAttribute('style','display:block');

 document.getElementById('body').appendChild(ans);

 </script>
 </head>

enter code here



 <body id='body'>

 </body>

 </html>

Upvotes: 0

Eli Grey
Eli Grey

Reputation: 35860

Yes, document.createElement("div"). For appending it where you want it, it's theParentElementYouWantToAppendTo.appendChild(theDivYouCreated).

Edit: And for the floating thing, do theDivYouCreated.style.position = "fixed".

Upvotes: 4

mplungjan
mplungjan

Reputation: 177960

Here http://docs.jquery.com/UI/Dialog

Overview

A dialog is a floating window that contains a title bar and a content area. The dialog window can be moved, resized and closed with the 'x' icon by default.

If the content length exceeds the maximum height, a scrollbar will automatically appear.

A bottom button bar and semi-transparent modal overlay layer are common options that can be added.

Upvotes: 1

Related Questions