how to get img src value without img id? (with javascript)

ababababa<img src="">ababababa

Recommended Answers

All 5 Replies

getElementsByTagName() would give you a list of nodes.

it gives me error :
[object HTMLCollection]

That's not an error, it's a list.

Once you have the items in the collection, you can access the items. Here is an example that should get you going...


<img src="images/image1.jpg" />
<img src="images/image2.jpg" />

    var images = document.getElementsByTagName("img"); 
    for (var i = 0; i < images.length; i++) { 
        var source = images[i].getAttribute("src"); 



The output in the JavaScript console would be...


got it now, getElementsByTagName(), mr. JorgeM you are right. thank you. thread close.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, learning, and sharing knowledge.