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

Popular posts from this blog

node.js - Using Node without global install -

How to access a php class file from PHPFox framework into javascript code written in simple HTML file? -

java - Null response to php query in android, even though php works properly -