JavaScript Mastering Web-css and Dom_javascript skills

Source: Internet
Author: User
Tags visibility

Recommended reading: JavaScript Harness Web-dom

Dom is a world Wide Web-standard HTML manipulation that can achieve more control than innerHTML features

Here are the HTML code and CSS code

<!doctype html>
 
 

By changing the whole style class of the node, classname the characteristic of the node to achieve dramatic style change.

DOM provides access to element style classes through the ClassName attribute of node properties

Alert (document.getElementById ("Span1"). ClassName);

Change the appearance of an element by changing the name of the CSS style class

 
 

Similarly, we can also use onmouseover () and onmouseout () events to control the style of the element here.

<span id= "Span1" class= "Class1" onmouseover= "This.classname= ' class2 '" "onmouseout=" This.classname= ' Class1 ' "" >

Although this effect is generally used to control the CSS, however, here only focus on the application of these tools, we can analogy

CSS style classes have nothing to do with JavaScript classes-they're completely different things

By accessing a single style feature of the node, the style node features a small amount of style changes

The style attribute of a node provides access to a single style attribute

<span id= "Span1" class= "Class1" onmouseover= "This.classname= ' class2 '" "onmouseout=" This.classname= ' Class1 ' "style = "Visibility:hidden" >

Style= "Visibility:hidden" indicates that the element is hidden

Page elements can be dynamically displayed or hidden using the visibility style features of element objects (Display:none/display:block can also be used to hide and display elements)

Dom can create any HTML element at will, including, of course, text paragraphs

Document.createelement () is used to create an HTML tag that is marked with a signature

Document.createelement ("P") creates a P tag

Another: document.createTextNode () is used to create paragraphs of text, arguments are text content

var pelem=document.createelement ("P");//create a P tag

Pelem.appendchild (document.createTextNode ("Hello wearezero!")); /Add child element text to P tag

document.getElementById ("Span1"). AppendChild (Pelem);//Add the P label and its child elements to the Span1 tab

Appendix:

Use the createelement () method of the Document object to create any HTML element

If you want the text content of the new element, you must create a text content child element and attach it to the element

By carefully adding and removing nodes from the DOM tree, the Web page can be disassembled and reorganized at will

JavaScript control page-CSS and Dom Introduction to here, hope to help you!

Related Article

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.