A.User,
рабочий код
<html>
<head>
</head>
<body>
<div class="pages">
<a href="http://site.com/page/2/">2</a>
<a href="http://site.com/page/3/">3</a>
<a href="http://site.com/page/4/">4</a>
<a href="http://site.com/page/5/">5</a>
<a href="http://site.com/page/6/">6</a>
<a href="http://site.com/page/7/">7</a>
<a href="http://site.com/page/8/">8</a>
<a href="http://site.com/page/9/">9</a>
<a href="http://site.com/page/10/">10</a>
<a href="http://site.com/page/11/">11</a>
</div>
<script>
function goURL(k) {
alert(k);
}
var container = document.querySelector('.pages');
if (container) {
container.querySelectorAll('a[href]').forEach(function (node) {
var href = node.getAttribute('href');
node.addEventListener('click', function (e) {
e.preventDefault();
goURL(href);// onClick - you function name
});
node.href = '#';
});};
</script>
</body>
</html>
или так
<html>
<head>
<script>
document.addEventListener( "DOMContentLoaded" , function() {
function goURL(k) {
alert(k);
}
var container = document.querySelector('.pages');
if (!container) {
return;
};
container.querySelectorAll('a[href]').forEach(function (node) {
var href = node.getAttribute('href');
node.addEventListener('click', function (e) {
e.preventDefault();
goURL(href);// onClick - you function name
});
node.href = '#';
});
});
</script>
</head>
<body>
<div class="pages">
<a href="http://site.com/page/2/">2</a>
<a href="http://site.com/page/3/">3</a>
<a href="http://site.com/page/4/">4</a>
<a href="http://site.com/page/5/">5</a>
<a href="http://site.com/page/6/">6</a>
<a href="http://site.com/page/7/">7</a>
<a href="http://site.com/page/8/">8</a>
<a href="http://site.com/page/9/">9</a>
<a href="http://site.com/page/10/">10</a>
<a href="http://site.com/page/11/">11</a>
</div>
</body>
</html>