New element Selection Method 1, Queryselector: The parameter is a CSS selector, returns the first DOM element that conforms to the selector, and returns no null. ie8+
1 <DivID= "Div1"class= "Div">Div1</Div>2 <DivID= "Div2"class= "Div">Div2</Div>3 <DivID= "Div3"class= "Div">Div3</Div>4 <Script>5 //var oDiv1 = document.queryselector (' #div1 ');6 //var oDiv1 = document.queryselector (' div ');7 varODiv1=Document.queryselector ('. Div');8 9 ODiv1.style.background= 'Red';
2. Queryselectorall: The parameter is a CSS selector; Returns a DOM collection that conforms to the selector, without returning an empty collection. Ie8+3, Getelementsbyclassname: Gets the collection of elements through the class name. ie9+Classlistclasslist: A collection of classes of elements. Classlist related properties and methods: Length: Length add: Adds the corresponding class remove: Removes the corresponding class toggle: Switches class, exists on delete, does not exist Add Item: Access class name According to index contains: judging is Contains the corresponding Classjson to implement object depth or shallow copy
1 var OA = {name: ' Hum ' }, 2 oB = {}, 3 str = "; 4 5 str = 6 oB = Json.parse (str); 7 Console.log (ob.name); // Hum 8 ob.name = ' Tyx ' ; 9 Console.log (oa.name); // Hum
Data customization is simple to use:
1 <DivID= "Div"Data-name= "Hum"Data-real-name= "Tyx">Div</Div>2 <Script>3 varOdiv=Document.queryselector ('#div');4 Console.log (oDiv.dataset.name);//Hum5 Console.log (oDiv.dataset.realName);//Tyx6 </Script>
HTML5 delay load Jsdefer:onload trigger before loading the JS file, only the external JS file to take effect, multiple defer coexistence when the load order cannot be determined. Async: Loading JS files Asynchronously, the order is difficult to guarantee, to load the independent JS. LABJS Library: Dynamically load script files in parallel and manage the order in which the load script files are executed. History management triggers History Management: 1, page jump 2, change hash 3, Pushstatehash value Change event: Window.onhashchange = function () {};p use of ushstate: Must be run on the server. History.pushstate (data, title, address) Window.onpopstate = function (EV) {Console.log (ev.state)}
HTML5 new Features