JS operation HTML text, attributes, element nodes and CSS

Source: Internet
Author: User

<! DOCTYPE html>

<meta charset= "UTF-8" >
<title></title>
<style type= "Text/css" >
. divred {
Border:solid 1px red;
}
</style>

<body>
<input type= "button" id= "value=" Testattribute "onclick=" Testattribute ();/>
<ol>
<li> (object. property) element is an object. The </li> property is the property of the object--the value of the custom property is not obtained;
<li> (object. Get/setatrribute) can manipulate custom properties--can only be used to obtain a constant value </li>
</ Ol>
<input type= "button" id= "value=" Testtext "onclick=" Testtext (); "/>
<ol>
<li>innerhtml</li>
<li>innertext</li>
</ol>

<input type= "button" id= "" value= "Testcss" onclick= "testcss ();"/>
<ol>
<li> </li>
<li> concrete style </li>
</ol>
<input type= "button" ID = "value=" Testnode "onclick=" Testnode ();/>

<input type= "text" id= "uname" value= "Beijing Shang Academy" abc= "123456"/>
<div id= "Showdiv" > Beijing Shang Academy is a good school </div>
<div id= "oper" class= "divred" >
<input type= "text" id= "school" value= "Beijing Shang Academy"/>
</div>
</body>
<script type= "Text/javascript" >
function Testattribute () {
var uname = document.getElementById ("uname");
Action Properties
Uname.value = "Shang Academy";
Uname.type = "button";
Alert (uname.value + "----" + uname.type);
Action Properties
Alert (Uname.getattribute ("type"));
Uname.setattribute ("Type", "button");
Alert (Uname.getattribute ("abc"));
Alert (Uname.getattribute ("value"));
}

function Testtext () {
var div = document.getElementById ("Showdiv");
Manipulating text
div.innerhtml = "Welcome to BJSXT";
alert (div.innerhtml);
div.innerhtml = "

}

function Testcss () {
var div = document.getElementById ("Showdiv");
Operation class
Div.classname = "divred";
Manipulating Specific styles
Div.style.height = "200px";
Div.style.width = "600px";
Div.style.backgroundColor = "Gray";
Div.style.lineHeight = "200px";
Div.style.fontSize = "40px";
div.style.textAlign = "center";
div.style.fontFamily = "in italics";
}

function Testnode () {
var div = document.getElementById ("oper");
var school = document.getElementById ("school");
Create a Node
var n = document.createelement ("input");
N.type = "button";
N.value = "BJSXT" + math.random ();
N.onclick = function () {
alert (this.value);
This.parentNode.removeChild (this);
};
Adding nodes
Div.appendchild (n);
Inserting nodes
Div.insertbefore (n, school);
Replace node
Div.replacechild (n, school);
Delete a node
Div.removechild (school);
}
</script>

JS operation HTML text, attributes, element nodes and CSS

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.