// Specify div(s)
const fieldNames = ['.more-link', '#featured-posts a', '.page-link a'];
// Select div(s)
const selectFields = fieldNames.map((field) => document.querySelectorAll(field));
selectFields.forEach((e, i) => {
if (selectFields.length > 0) {
// Get links within a specificied div
const linkArray = Array.prototype.slice.call(e);
// Add target="_blank" attribute to links
linkArray.forEach((link) => link.setAttribute('target', '_blank'));
}
});
[I]Github: https://gist.github.com/serdarwork/e1a37dd1015f22e5add5813b477f8478