Sunday, June 2, 2024
 Popular · Latest · Hot · Upcoming
103
rated 0 times [  108] [ 5]  / answers: 1 / hits: 54152  / 13 Years ago, mon, january 16, 2012, 12:00:00

I have a parent div gal1, inside which there can be further divs and content, but only one img element without an id as you can see below. Now I want to use only Javascript (no jQuery) to change the style of this image, using gal1 as argument (because the rest of the structure inside this div may vary, only this one image will always be there somewhere). I couldn't find any other stackoverflow question that addresses exactly my situation.



<div class=gallery-preview id=gal1>
<div class=gallery-preview-img id=gal-img1>
<img src=galleries/kevin-carls/Monks.jpg>
</div>
<div class=gallery-preview-text id=gal-text1>
<span class=gallery-name href=>Road to India</span><br/>
<span class=artist-name href=>Kevin Carls</span>
</div>
</div>

More From » html

 Answers
59

Than you can make use of method called getElementsByTagName('img') than you should get image and update it.



document.getElementById(gal1).getElementsByTagName('img');

[#88000] Saturday, January 14, 2012, 13 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
naya

Total Points: 60
Total Questions: 87
Total Answers: 87

Location: Guam
Member since Fri, Jun 18, 2021
3 Years ago
;