Maybe this one:
<a class="one" href="#">Link 1</a>
<a class="two" href="#">Link 2</a>
<a class="one" href="#">Link 3</a>
<a class="one" href="#">Link 4</a>
<a class="two" href="#">Link 5</a>
<a class="two" href="#">Link 6</a>
<a class="one" href="#">Link 7</a>
<button id="btn">Click me</button>
and JS
var button = document.getElementById('btn');
var className = "one";
button.addEventListener('click', function() {
find(className);
});
function find(str) {
var items = document.getElementsByClassName(str);
for(var i=0; i<items.length; i++) {
console.log(items[i].innerHTML);
}
}
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…