JavaScript document 情報取得・書き換え

a タグ関連

<div id="sample">
  <ul>
    <li><a href="http://127.0.0.1/A">A</a></li>
    <li><a href="http://127.0.0.1/B">B</a></li>
    <li><a href="http://127.0.0.1/C">C</a></li>
  </ul>
</div>

const linksSample = document.querySelector('#sample a');

console.log(linksSample); // object
console.log(linksSample.outerHTML); // string : <a href="http://127.0.0.1/A">A</a>
console.log(linksSample.localName); // string : a
console.log(linksSample.href); // string : http://127.0.0.1/A
console.log(linksSample.getAttribute('href')); // string : http://127.0.0.1/A
console.log(linksSample.getAttributeNames('href')); // object : ['href']

linksSample.setAttribute('target', '_blank'); // target='_blank' 追加
linksSample.setAttribute('rel', 'noopener noreferrer'); // rel='noopener noreferrer' 追加