I'm working on a userscript for YouTube and I need to retrieve the href attribute of an <a>
tag through the class name.
This was my attempt but it just returned "undefined":
var x = document.getElementsByClassName("mix-playlist").getAttribute("href");
console.log(x);
<a class="XY XY XY mix-playlist XY" href="XY"></a>
Thanks for your help!
Nevermind, I figured it out. I just had to move it into this function:
document.addEventListener("DOMContentLoaded", function() {
and split the resulting array.
Sorry for the duplicate but I just couldn't gather much information after looking through stackoverflow questions for 20 minutes.