我如何訪問<h2>
標記。我目前的選擇是一個<span>
元素,它是按鈕的子元素。我試過,但只能得到父母是按鈕。使用Javascript的Dom遍歷
請注意我有多個<Span>
元素在頁面上
請注意我需要純粹的Java腳本,因爲我使用自定義的Java腳本這是谷歌標籤管理器。
所以基本上iam使用下面的代碼。只是平視的{{clickelemet}}這裏是<span>
元件 <> 函數(){
var el = {{Click Element}}.parentElement.querySelector('h2');
return el ? el.textContent || el.innerText : undefined;
}
--------------- HTML元素--- --------------------
<div class="col-12 col-md-10 offset-md-1">
<h2>Blockchain – Opportunities & Challenges across Multiple Industries</h2>
<p>It began with Bitcoin, but now it has spread. Blockchain has the potential to radically transform the way industries do business. Here are some examples of success and challenges as blockchain inserts itself into transactions and process.</p>
<button class="panel__link panel__link--btb" aria-expanded="false" aria-controls="panel-1">
<i>+</i> <span>Expand article</span>
</button>
</div>
感謝您的支持。
後一個工作片斷 –
而不是使用大括號,請給我們一個真實的點擊元素ID及其對應的HTML元素。 – asmmahmud
'span'元素在哪裏? – clabe45