Dom對象,控制html元素

來源:互聯網
上載者:User

標籤:

document.getElementsByName(name)//返回帶有指定名稱的節點對象的集合。
document.getElementsByTagName(Tagname)//返回帶有指定標籤名的節點對象的集合。返回元素的順序是它們在文檔中的順序。
node.firstChild//返回‘childNodes’數組的第一個子節點。如果選定的節點沒有子節點,則該屬性返回 NULL。
node.lastChild//返回‘childNodes’數組的最後一個子節點。如果選定的節點沒有子節點,則該屬性返回 NULL。
elementNode.parentNode//擷取指定節點的父節點
elementNode.parentNode.parentNode//訪問祖節點

nodeObject.nextSibling//返回某個節點之後緊跟的節點(處於同一樹層級中)如果無此節點,則該屬性返回 null。

nodeObject.previousSibling//返回某個節點之前緊跟的節點(處於同一樹層級中)如果無此節點,則該屬性返回 null。
appendChild(newnode)//在指定節點的最後一個子節點列表之後添加一個新的子節點
insertBefore(newnode,node);//在已有的子節點前插入一個新的子節點。

參數:


newnode: 要插入的新節點。


node: 指定此節點前插入節點。

 
nodeObject.removeChild(node);//node :必需,指定需要刪除的節點。
node.replaceChild (newnode,oldnew )// 實現子節點(對象)的替換。返回被替換對象的引用參數:newnode : 必需,用於替換 oldnew 的對象。 oldnew : 必需,被 newnode 替換的對象。
document.createElement(tagName)//建立元素節點參數:tagName:字串值,這個字串用來指明建立元素的類型。注意:要與appendChild() 或 insertBefore()方法聯合使用,將元素顯示在頁面中。
document.createTextNode(data)//建立新的文本節點,返回新建立的 Text 節點參數:data : 字串值,可規定此節點的文本。

 

elementNode.getAttribute(name)//通過元素節點的屬性名稱擷取屬性的值。說明:1. elementNode:使用getElementById()、getElementsByTagName()等方法,擷取到的元素節點。2. name:要想查詢的元素節點的屬性名稱字
elementNode.setAttribute(name,value)setAttribute() //方法增加一個指定名稱和值的新屬性,或者把一個現有的屬性設定為指定的值。說明:1.name: 要設定的屬性名稱。2.value: 要設定的屬性值。

 

 

 
 

Dom對象,控制html元素

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.