Reputation: 2113
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
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
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
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