I tried to count the links on the page using JS, but got different results. Why is there a difference?
var intLNK = document.links.length; console.log(intLNK); var intA = document.getElementsByTagName("a").length; console.log(intA);
Quote from MDN
Reference property returns a collection of all the elements <area>and <a>the document with a value for the attribute href.
<area>
<a>
href
document.getElementsByTagName("a").length;
will return anchor elements regardless of attribute href. you can use
document.querySelectorAll('a[href]').length
to get the number of anchors that have an attribute href.
If you are interested in the performance of the two, see https://jsperf.com/document-links-vs-document-queryselectorall-a Thanks Robert Weber
document.links a ( <area>), href, - .
document.links
a
(mdn)
a href
, HTML.
1) . <A Name = "Section1"> ... </A>
<A Name = "Section1"> ... </A>
2) . < A HREF = "target location"> ... </A>
< A HREF = "target location"> ... </A>
document.links.length HREF, document.getElementsByTagName("a").length A .
document.links.length
document.getElementsByTagName("a").length
.
, href, . .
href , jquery,
$('a[href]').length
Source: https://habr.com/ru/post/1662227/More articles:Android permissions questions - javaCordoba no sound on bluetooth speakers - androidHow to match strictness with same width in Boost log - c ++How to close all popups programmatically in mapbox gl? - javascriptHow to install NPM package from GitHub for Meteor? - npmBeautifulSoup4 throws an error in Python 3.x - pythonCalculation using float in macros in C - cЗначение по умолчанию для поля в наборе изменений - elixirConvert Makefile to CMakeLists, where to start - cmakehttps://translate.googleusercontent.com/translate_c?depth=1&pto=aue&rurl=translate.google.com&sl=ru&sp=nmt4&tl=en&u=https://fooobar.com/questions/1662232/selenium-test-fails-to-start-using-operadriver&usg=ALkJrhiRzdDPaZg5r6bnWlQwecbk_8JGWAAll Articles