Learn about dom manipulation javascript tutorial, we have the largest and most updated dom manipulation javascript tutorial information on alibabacloud.com
node does not render the document's "existence structure". This avoids the performance issues inherent in the HTML collections mentioned earlier in this chapter (and potential logical problems).If you do not use Queryselectorall (), the code that achieves the same goal will be verbose:var elements = document.getElementById (' menu '). Getelementsbytagname_r (' a ');In this case elements will be an HTML collection, so you'll also need to copy it into an array if you want toQueryselectorall () Th
access to HTML documents (such as body, form, div, textarea, etc.) and how to do so.Three. BOM
The BOM is an abbreviation for the browser object model.
BOM provides an object that is independent of the content and interacts with the browser window
Because the BOM is primarily used to manage the communication between Windows and Windows, its core object is window
A BOM is composed of a series of related objects, and each object provides many methods and properties
BOM la
', ' O ', ' M ', node manipulation, attribute manipulation (same directory)Content:1. Dom Concept:' D ': web document = "Document object (manipulating object);' O ': Same as chapter II = "CONTENT =" 3rd; ' m ': direct translation is ' model ' or ' map ', which is the ability to read DOM information through '
, Part 4" Did a detailed introduction, here I also tidy up:the key to solving the problem is to reduce the reflow caused by DOM manipulation. Nicholas summarizes some of the methods:"1" performs as many change operations as possible outside the DOM. Demo:Bad practices for (var i=0; i Better practices//Use containers to store temporary changes, and finally update
The DOM itself has many types, which are described in the previous chapter, such as element types: The elements node, or the text type;
One DOM type
Type name DescriptionNode represents a uniform interface for all types of values, IE is not supported;Document indicates the type of file;Element represents the node type;Text indicates the type of the literal node;Comment represents the type of annotation in
="Fruit" name="Li4">Orangeli> ul> body> Methods for manipulating node textThe use of these methods is similar to string manipulation, and this memo is no longer an example.
AppendData (text): Adds text to the end of the text;
DeleteData (offset, count): Deletes count characters starting at offset;
InsertData (offset, text): Inserts text at offset;
ReplaceData (offset, count, text): Use text to replace the count character fro
The DOM operations of this section of JavaScript mainly include the following:
Select elements by ID, name, tag name;
Get and set element attributes through GetAttribute and SetAttribute;
Get the parent element through ParentNode, createelement dynamically create nodes, AppendChild, and removechild dynamically add or remove nodes.
Basic Concepts 2.1.1 What is DOMDom is the short name o
expression shown in the Calculation window, you append the specified text to the end of the page. Note that target is the variable name, which indicates the selected node, which is the BODY element.
Figure 5-11 Using the JavaScript calculation window to dynamically add a text node (left) in the body of the page, and the results in the Browser pane (right)
The CSS style rules and the computed style information type display information about the sele
What is DOM?The DOM is the Document Object model. Is the programming interface for HTML and XML documents. It provides a structured representation of the document and defines a way to access the structure from within the program, altering the structure, style, and content of the document. The DOM parses a document into a collection of structures consisting of nod
Original article: speeding up javascript: working with the DOM
Author: keekim Heng, Google Web Developer
Http://www.blogjava.net/emu/archive/2010/03/01/314185.html
When we develop Internet rich applications (RIA), we often write some JavaScript scripts to modify or add page elements. These tasks are completed by Dom
First, jquery operation Dom-queryHTML operations-HTML (): Reads or modifies the HTML content of a node, similar to the innerHTML property in JavaScript650) this.width=650; "src=" Http://s5.51cto.com/wyfs02/M01/7E/6C/wKiom1b-X2yxgKrTAABY4VoUGQs797.png "title=" Web.png "alt=" Wkiom1b-x2yxgkrtaaby4vougqs797.png "/>Text manipulation-Text (): Reads or modifies the text content of the node, similar to the Textcon
Splittext ()."DocumentFragment Type"Of all node types, only documentfragment does not have a corresponding tag in the document. Although you cannot add a document fragment directly to a document, you can use it as a "warehouse" where you can save nodes that may be added to the document in the future. The nodes in the document fragment are not part of the document tree. Adding the contents of a document fragment to a document by AppendChild () or insertbefore (), even if the document fragment is
);
It would be nice to be able to delete an element without referencing the parent element.But I'm sorry. The DOM needs to be clear about the element you need to delete, and its parent element.
This is a common solution: find the child element that you want to delete, and then use its ParentNode property to find the parent element:var Child=document.getelementbyid ("P1");Child.parentNode.removeChild (child);
HTML
allows programs and scripts to dynamically access and update content, architectures, and file styles. The file can be further processed and the result is returned to the display page.
In fact, I still see it in the cloud, so we can understand it as a matter of fact, DOM is a unified solution for the convenience of programming and fast transmission, based on the tree specification, it has nothing to do with the browser. The basic idea of
the element is found, the method returns the element in the form of an object (in X).If the element is not found, the X will contain null.Find an instance of an HTML element with a tag nameThis example finds the element that id= "main" and then looks for all the var X=document.getelementbyid ("main"); var y=x.getelementsbytagname ("P");Tip: Finding HTML elements through the class name is not valid in IE 5,6,7,8.HTML DOM TutorialsIn the remainder of t
) {
if (typeof e = = "string") E = document.getElementById (e);
E.id = E.id.replace (New RegExp ("\\b" +e.id + "\\b\\s*", "G"), "");
E.classname = E.classname.replace (New RegExp ("\\b" +c+ "\\b\\s*", "G"), "");
};
3. Add the following elements to the body
Copy Code code as follows:
Effect:
No style added.After the style is added.Summary: DOM document manipulation, i
As we know, Dom is an application interface for manipulating XML and HTML documents, and scripting DOM operations can be costly. There is an apt analogy, the DOM and JavaScript (here refers to ecmscript) each imagined as an island, they are connected with a toll bridge, ECMAScript each access to the
The js object relational diagram facilitates dom operations. For more information, see. Are common attributes. Js object Relationship Diagram
JavaScript Object Reference Manual
This reference manual describes the attributes and methods of each object and provides examples.
Array
Boolean
Date
Math
Number
String
RegExp
Global
Browser Object Reference Manual
This reference manual describes the attribu
elementObj.shift () Removing elements from the headObj.splice (Start, DeleteCount, value, ...) inserting, deleting, or replacing elements of an arrayObj.splice (n,0,val) specify position insert elementObj.splice (n,1,val) specifying position substitution elementsObj.splice (n,1) specify location Delete elementObj.slice () slicesObj.reverse () reversalObj.join (Sep) joins the array elements to construct a string.Obj.concat (val,..) connection arrayObj.sort () sorting an array element Dictionary
Career development, code 100 days--2018-04-14The basic knowledge of DOM operations in JavaScript is the manipulation of DOM elements for pruning. The main performance is with the operation of HTML elements, as well as the operation of CSS styles. Its main application knowledge is as follows:Through the basic understand
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.