Introduction to HTML DOM and new features
Introduction
In the core DOM, the properties and methods provided can already operate web pages. Why do we need HTMLDOM?
If in the core DOM, the node level in the web page is very deep, it will be very troublesome to access this node.
Then, HTMLDOM provides a method to directly find nodes by id, instead of starting from the HTML root node.
##New features of HTMLDOM
- Each HTML tag corresponds to an element object. For example: <img> corresponds to an image object
- . The attributes of each HTML tag correspond to the attributes of the corresponding element object in a one-to-one correspondence.
<!DOCTYPE HTML> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> <title>php.cn</title> <script type="text/javascript"> window.onload = function(){ //獲取網(wǎng)頁中id=img01的圖片對象 var imgObj = document.getElementById("img1"); //修改圖片的屬性的值,圖片標記的屬性,元素對象也能用。 imgObj.src = "/upload/course/000/000/009/580af7f52278b486.jpg"; imgObj.width = 400; imgObj.border = 2; imgObj.style = "cursor:pointer"; imgObj.title = "唯美圖片"; //核心DOM中的屬性方法,元素對象都能用 imgObj.parentNode.bgColor = "#f0f0f0"; } </script> </head> <body > <img id="img1" src="/upload/course/000/000/009/580ae23c4a88a881.jpg" /> </body> </html>