1 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 2 <html xmlns="http://www.w3.org/1999/xhtml"> 3 <head> 4 <meta http-equiv="Content-Type" content="text/html;charset=UTF-8" /> 5 <title></title> 6 </head> 7 <body> 8 <div id="myDiv"></div> 9 <script type="text/javascript" src="test33.js"></script> 10 </body> 11 </html>
1 var div = document.getElementById("myDiv"); 2 div.setAttribute("id", "someOtherId"); 3 div.setAttribute("class", "ft"); 4 div.setAttribute("title", "Some other text"); 5 div.setAttribute("lang", "fr"); 6 div.setAttribute("dir", "rtl"); 7 8 console.log(div.getAttribute("id")); 9 console.log(div.getAttribute("class")); 10 console.log(div.getAttribute("title")); 11 console.log(div.getAttribute("lang")); 12 console.log(div.getAttribute("dir")); 13 14 div.id = "sds"; 15 div.align = "left"; 16 console.log(div.getAttribute("id")); 17 console.log(div.getAttribute("align")); 18 19 div.removeAttribute("id"); 20 console.log(div.getAttribute("id"));