I have a code with the following DOM Tree:
-
$('#blogPagination').find('a').attr('href');
This should find all a
elements in the specified area, the get the href
of them, assuming that you've already got jQuery and all that good stuff set up.
If you have multiple a
elements, you could do something like this:
$('#blogPagination').find('a').each(function() {
console.log($(this).attr('href'));
});
This will print out each href
of each a
in that div
.
If you need to prevent the link from changing the page, you need to add a click handler to the a
elements.
$('#blogPagination').on('click', 'a', function(e) {
e.preventDefault();
console.log($(this).attr('href'));
});
This will prevent the user from being taken to the link, and get the href
of the link when clicked.
Is this what you want?