首页 > 解决方案 > How to recover the title of an

问题描述

标签: javascripttags

解决方案


You can get all the elements with the tag a by

document.getElementsByTagName("a")

It returns a HTMLCollection of all elements with the tag a.

Now we can loop over it and check if there is an element which has a title starts with 'FR' using Strings startsWith() method.

let allA = document.getElementsByTagName("a");
let found = false;
for(let l = 0; l < allA.length; l++){
  if (allA[l].title.startsWith('FR')) {
    found = true
  }
}

console.log(found);
<a href="project/150" title="FR - This is an example" target="_blank">FR - This is an example"</a>


推荐阅读