[英]Extracting attribute from DOM element
我需要返回嵌套在DOM元素中的字符串。 該字符串看起來像一個值,該值存儲在稱為“選擇器”的鍵或屬性中
我一直在使用控制台嘗試獲取該字符串。
我的HTML =
此JavaScript / JQuery:
console.log($(this.nextSibling.data));
記錄到控制台
我努力了:
console.log($(this.nextSibling.data.selector));
console.log($(this.nextSibling.data[selector]));
console.log($(this.nextSibling.data(selector)));
等等,運氣不佳。 由於我不確定我什至不知道該數據結構是什么,因此我不知道如何從類似鍵的“選擇器”中返回“ gi”(在此示例中)
我怎么能得到那串?
只需使用this.nextSibling.data
(無需將其轉換為jQuery對象)
當this.nextSibling
是textNode(或commentNode)時,它的data
屬性返回該節點的textContent(characterData)。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.