简体   繁体   中英

Trying to retrieve 'src' of class gives error

I need to retrieve the html link that is in src inside a div on a web page, the div looks like this:

<iframe width="100%" class="idemo2" frameborder="0" scrolling="no" marginheight="0" marginwidth="0" src="some/private/link">
</iframe>

I have already managed to get the contents of this class inside a variable using this little bit of code:

var l = document.getElementById("demo-left").getElementsByClassName("idemo2")

But when I try to retrieve the src, either by adding .src or .getAttribute("src") to the back of the above placed code, or directly to the variable, it gives back the value of 'undefined'.

My question is how do I get the src inside my variable instead of the whole Class?

jQuery is also an option to use, but I have not studied how to use jQuery (yet).

jQuery的

var imgSrc = $(".idemo2").attr('src');

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM