当前位置: 首页>>代码示例 >>用法及示例精选 >>正文


HTML DOM Aside用法及代码示例


DOM Aside对象用于表示HTML <Aside>元素。 Aside元素由getElementById()访问。aside元素是html 5中的新增函数。语法:

document.getElementById("ID");

其中“id”是分配给aside标签的ID。
示例1:

<!DOCTYPE html> 
<html> 
  
<head> 
    <title>aside tag</title> 
    <style> 
        .gfg { 
            font-size:30px; 
        } 
          
        aside { 
            font-size:40px; 
            color:#090; 
            font-weight:bold; 
        } 
          
        p { 
            font-size:20px; 
            margin:20px 0; 
        } 
    </style> 
</head> 
  
<body> 
    //Assign ID to the aside tag. 
    <aside id="GFG"> 
        <h1>GeeksforGeeks</h1> 
        <p>A computer science portal for geeks</p> 
    </aside> 
      
    <h2 style="font-size:35px;">DOM Aside object</h2> 
    <button onclick="myGeeks()">Submit</buttom> 
        <script> 
            function myGeeks() { 
                var w = document.getElementById("GFG"); 
                w.style.color = "red"; 
            } 
        </script> 
</body> 
  
</html>                

输出:
在单击按钮之前:

单击按钮后:

示例-2:可以使用document.createElement方法创建Aside Object。

<!DOCTYPE html> 
<html> 
  
<head> 
    <title>aside tag</title> 
    <style> 
        .gfg { 
            font-size:30px; 
        } 
          
        p { 
            font-size:20px; 
            margin:20px 0; 
        } 
    </style> 
</head> 
  
<body> 
    <center> 
        <h2 style = "font-size:35px;">DOM Aside object</h2> 
        <button onclick="myGeeks()">Submit</buttom> 
            <script> 
                function myGeeks() { 
                    var w = document.createElement("ASIDE"); 
                    w.setAttribute("id", "GFG"); 
                    document.body.appendChild(w); 
  
                    var heading = document.createElement("H3"); 
                    var text1 =  
                    document.createTextNode("GeeksForGeeks"); 
  
                    heading.appendChild(text1); 
                    document.getElementById("GFG" 
                    ).appendChild(heading); 
  
                    var para = document.createElement("P"); 
                    var text2 = document.createTextNode( 
                    "A Computer Science Portal for Geeks."); 
                    
                    para.appendChild(text2); 
                    document.getElementById("GFG" 
                    ).appendChild(para); 
                } 
            </script> 
</body> 
  
</html>  

输出:
在单击按钮之前:

单击按钮后:

支持的浏览器:下面列出了DOM Aside Object支持的浏览器:

  • 谷歌浏览器
  • IE浏览器
  • Firefox
  • Opera
  • Safari




相关用法


注:本文由纯净天空筛选整理自ManasChhabra2大神的英文原创作品 HTML DOM Aside Object。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。