我如何访问<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