-1

I have no experience in javascript. Basically i want to get image src and aria-label name using javascript. I try many scripts on console like this

var image = document.getElementsByClassName("");
var src = image.getAttribute('src');
console.log(src);

but did't get solution. Can any one please tell me how i can get this.

enter image description here

URl is that i want to get using javascript. Thanks

AzKa
  • 35
  • 1
  • 10

2 Answers2

1

Your image is not in src attribute. It is in background-image.

    var image = document.getElementsByClassName("profpic")[0];
    var image= image.css('background-image');
    var src = image.replace('url(','').replace(')','').replace(/\"/gi, "");
    alert(src);
Anurag
  • 128
  • 5
  • **Error** VM347:2 Uncaught TypeError: image.css is not a function(…)(anonymous function) @ VM347:2 – AzKa Sep 27 '16 at 12:27
  • Because .css() is a jQuery function [reference](http://api.jquery.com/css/) so you should include jQuery in your script. – Luigi Cerone Oct 03 '16 at 08:45
-1
var elem=document.getElementsByClassName("img profpic")[0];
var match=elem.style.backgroundImage.match(/url\(\"(.*?)\"\)/)

var aria_label=elem.getAttribute("aria-label");
var background_url=match[1];
  • Please edit with more information. Code-only and "try this" answers are discouraged, because they contain no searchable content, and don't explain why someone should "try this". – abarisone Sep 27 '16 at 14:23