javascript - How to get all the src and href attributes of a web site -
i want way src , href attributes(like images , links) in website. how can make in javascript? try this:
var ilist=document.links; for(var = 0; < ilist.length; i++) { if(ilist[i].href) { alert(ilist[i].href) } } but something, not works. works . want href's , src's tags. can me?
using plain js can do: string give queryselectorall normal css selector.
var srcnodelist = document.queryselectorall('[src],[href]'); (var = 0; < srcnodelist.length; ++i) { var item = srcnodelist[i]; if(item.getattribute('src') !== null){ alert(item.getattribute('src')); } if(item.getattribute('href') !== null){ alert(item.getattribute('href')); } } here's fiddle: https://jsfiddle.net/vpbepvco/1/
Comments
Post a Comment