我的HTML是:
<div class="alignleft">
<a href="http://cismdomain.com/articles/page/2/">« Older Entries</a>
</div>
我想将“旧条目”更改为“上一个”.
我的JavaScript代码是:
var oldentries = document.querySelector('.alignleft');
var ainside = document.getElementsByTagName('a');
oldentries.ainside.innerHTML = "PrevIoUs";
但这让我不确定.
解决方法:
一旦使用Document.querySelector()获取类’.alignleft’的元素,您还可以执行oldentries.querySelector(‘a’);.获取旧条目中的’a’元素,然后更改element.innerHTML:
var oldentries = document.querySelector('.alignleft'),
ainside = oldentries.querySelector('a');
ainside.innerHTML = 'PrevIoUs';
<div class="alignleft">
<a href="http://cismdomain.com/articles/page/2/">« Older Entries</a>
</div>