JS Dynamic Creation Div_javascript Skills

Source: Internet
Author: User
This is the original CSS style
. item{float:left;overflow:hidden;margin-left:8px;margin-top:10px;width:320px Height:
250px;background-repeat:no-repeat; Background-image:url (.. /images/bgred.jpg)}
curve{position:relative;width:320px height:250px; z-index:1 left:75px; top: -40px;
The dynamically created Div code is as follows:
for (j = 0;j*8 <str.length; J + +)
{
var mydiv = window.frames["Displayframe"].document.createelement ("div");
Mydiv.setattribute ("id", "itemdiv" +j);
Mydiv.style.stylefloat= "left";
Mydiv.style.overflow= "hidden";
Mydiv.style.marginleft= "8px";
mydiv.style.margintop= "10px";
Mydiv.style.width= "320px";
Mydiv.style.height= "250px";
mydiv.style.backgroundrepeat= "No-repeat";
Mydiv.style.backgroundimage= "url (image/bgred.jpg)"
window.frames["Displayframe"].document.body.appendchild (mydiv);
var curvediv =window.frames["Displayframe"].document.createelement ("div");
Curvediv.setattribute ("id", "curvediv" +j);
Curvediv.style.position= "relative";
Curvediv.style.zindex=1;
Curvediv.style.left= "75px";
curvediv.style.top= " -40px";
Curvediv.style.width= "320px";
Curvediv.style.height= "250px";
window.frames["Displayframe"].document.getelementbyid ("Divitem" +j). appendchild (Curvediv);
}
Add the div element to the HTML.
You can also define a span in HTML
window.frames["Displayframe"].document.getelementbyid ("Spanid"). AppendChild (Mydiv);
window.frames["Displayframe"].document.body.appendchild (mydiv);
IE and Firefox are supported.
The other thing to note is this CSS element
Floating effect: Float:left
In IE, the code is: mydiv.style.stylefloat= "left";
In the Firefox code is: mydiv.style.cssfloat= "left";
Other elements such as this:
In the CSS writing is generally: margin-left:8px
And in the dynamic increase needs to be removed-: mydiv.style.marginleft= "8px";
There is no careful study of case sensitive issues.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.