Home > Web Front-end > JS Tutorial > js code to control div and web page related attributes_javascript skills

js code to control div and web page related attributes_javascript skills

WBOY
Release: 2016-05-16 18:38:36
Original
925 people have browsed it

Dynamicly create 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:

Add, set:
(1). div.setAttribute("ok","ok?");
html:


(2). var ok = document.createAttribute("name");
div.setAttributeNode(ok) ;
html:

Get:
(1).div.getAttribute("ok" );//ok?
(2)var v = div.getAttributeNode("ok").value;// div.getAttributeNode("ok") obtains the //AttributeNode object.
Delete
(1).document.getElementById("id").removeAttribute("ok");//ok is the attribute name.
(2).document.getElementById("id").removeAttributeNode(ok);//ok is the AttributeNode object.

A very important method
document.getElementsByTagName

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template