Dynamically create a DIV: var div = document. createElement ("div ");
Set div attributes and styles:
Div. title = "this is a new div .";
Div. class = "newDivClass ";
Div. innerHTML = "Test create a div element! ";
Div. style. styleFloat = "left ";
Div. style. overflow = "hidden ";
Div. style. marginLeft = "8px ";
Div. style. marginTop = "10px ";
Div. style. width = "320px ";
Div. style. height = "250px ";
Div. style. backgroundRepeat = "no-repeat ";
Div. style. backgroundImage = "url (image/bgred.jpg )"
Add div to body: document. body. appendChild (div );
Set Attribute attributes:
Add and set:
(1). div. setAttribute ("OK", "OK? ");
Html: <div id = "id" style = "background-color: red;" OK = "OK? "/>
(2). var OK = document. createAttribute ("name ");
Div. setAttributeNode (OK );
Html: <div id = "id" style = "background-color: red;" name = ""/>
Obtain:
(1). div. getAttribute ("OK"); // OK?
(2) var v = div. getAttributeNode ("OK"). value; // div. getAttributeNode ("OK") obtains the // AttributeNode object.
Delete
(1).doc ument. getElementById ("id"). removeAttribute ("OK"); // OK indicates the attribute name.
(22.16.doc ument. getElementById ("id"). removeAttributeNode (OK); // OK is the AttributeNode object.
An important method
Document. getElementsByTagName