Discover javascript dom manipulation, include the articles, news, trends, analysis and practical advice about javascript dom manipulation on alibabacloud.com
During development, we occasionally encounter a problem like this: a DOM element on the page has been changed to a property, but we do not know which script has changed, you can use the source code search method. Indeed, this method often works for a relatively simple page. However, for relatively complex pages (for example, pages are embedded with many script files and fragments, large object-oriented implementations are used, and the implemented cod
Two ways to change the src attribute of a picture:
The 1,setattribute method is part of the "level 1th dom", which can set any property of an element node.
2,ELEMENT.SRC = Source; This is the way before "level 1th dom" appears, and it is now valid.
The advantage of "level 1th dom" is portability, and those old methods apply only to Web documents, and
JavaScript library for Reading Notes in JavaScript DOM programming art, javascriptdom
There are two ways to change the src attribute of an image:
1. The setAttribute method is an integral part of "level 1st DOM". It can be used to set any attribute of an element node.
2, element. src = source; this is the method before
Trinity's Web pageStructure layer: Created by markup language such as HTML or XHTML;Presentation layer: The CSS is responsible for the completion;Behavior layer: The issue of how content should respond to events. This is the domain dominated by the JavaScript language and Dom.SeparationUse (X) HTML to build the structure of the document;Use CSS to set the rendering effect of the document;Using DOM scripting
(condition)For loopfor (initial condition; test condition,; alter condition) {statements;}Six, functionDefines the syntax for a function:Function name (arguments) {statements;}Scope of the variableGlobal variables: can be referenced anywhere in the script. The scope is the entire script.Local variable: exists only inside the function that declares it.Global variables are masked when local variables declared in a function have the same name as global variables.Seven, ObjectAn object is a very im
This article mainly introduces how to obtain the class in dom using JavaScript, which involves the use of javascript to operate dom nodes, for more information about how to use JavaScript to obtain classes in dom, see the example
changing the ClassName property of any HTML element (dynamically setting a style class name)classname may contain a string of multiple classes, separated by a space between the class names. When set, you can control the new class by re-setting the stringor a class list. 6. Scripted style sheetsThe HTML Level 2 DOM standard defines a disabled attribute for The disabled value of the element can be set in JavaScript
JavaScript consists of three parts: ECMAScript, BOM, and Dom1. Core--ecmascript: Provide core language functions2. Document Object Model--dom: Provides methods and interfaces for accessing and manipulating Web page contentAn application Programming interface (API) for XML but extended for HTML.The DOM maps the page into a multi-layered node structure.Why use the
This article mainly helps you understand DOM events in javascript, solve the compatibility of DOM events, bubble DOM events, and reuse of DOM events. If you are interested, refer to the following, this article does not discuss tedious details. However, considering the reader
) {
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
This article mainly introduces the JavaScript location and size (1) -- correctly understands and uses the DOM attributes related to the size. For more information, see web development, inevitably, the problem of calculating the element size and position is solved by using some APIs provided by DOM in combination with compatibility, all the content is described in
The jquery object is the object that is generated after the DOM object is wrapped through jquery. jquery objects are unique to jquery, which can use the methods in jquery, but cannot use DOM methods, such as: $ ("#img"). attr ("src", "test.jpg"); The $ ("#img") here is the JQuery object.
Dom objects are some of the object operations inherent to
DOMDOM is the W3C standard. It defines the criteria for accessing HTML and XML documents. It provides a structured representation for the document, which can change the content and presentation of the document. DOM is an interface unrelated to browsers, platforms, and languages. Using this interface, you can easily access DOM as the W3C standard. It defines the criteria for accessing HTML and XML documents.
This article mainly introduces 11 methods for JavaScript to obtain DOM elements. This article uses 11 methods in four categories to summarize how to obtain DOM elements, for more information about how to update the style and content of a Web application, especially a Web application, you must obtain an element on the page. How to obtain the elements to be updated
DOM elements have some standard events. Generally, you only need to use the onclickfunction method. However, when you need to add multiple events to the DOM element, delete the event, or when Javascript is used to encapsulate controls, DOM elements have some standard events when a custom event is added to the encapsula
element node City.appendchild (liNode);//Create text node var textnode = document.createTextNode ("Homecoming Dream");//Add a text node to the child node Linode.appendchild (textnode);Replacement of the node:replacechild (): replaces one child node in a given parent element with another child nodevar reference = Element.replacechild (Newchild,oldchild);The previous parameter in the parentheses is the new value after the substitution, and the subsequent parameters are the nodes to be replaced.va
Browser has the function of rendering HTML, the HTML source code in memory to form a DOM object, is the document object.Inside the browser there is a JS interpreter/actuator/engine, such as Chrome's V8 engine.In the HTML to write a JS code, JS code is executed by the engine, the result of execution is often the operation of the DOM-common effects (image floating, text discoloration, etc.)The browser is "hos
This article mainly introduces the DOM operation details in jQuery and the 13-point JavaScript difference between Firefox and IE. For more information about how to achieve stable degradation and backward compatibility, the idea of tag separation, the first thing to do when writing JavaScript code each time should be necessary testing and inspection work:
Add the
This article mainly introduces how javascript uses DOM operations to implement simple message boards. it involves DOM operations in javascript and is very useful, for more information about how to use DOM in JavaScript to implemen
other methods we have described earlier. We can call it only through an element node object.The Setattribute:setattribute () method has a fundamental difference from them: it allows us to make changes to the value of the attribute node. Similar to the GetAttribute () method, the SetAttribute () method is also a function that can be called only through an element node object, but the SetAttribute () method requires that we pass two parameters to it:Firstchild.nodevalue:Suppose we already have a
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.