Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6848453
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T00:52:12+00:00 2026-05-27T00:52:12+00:00

Example: <div class=test><img src=test.jpg style=display:none; /></div> How to change that with javascript, I know

  • 0

Example:

<div class="test"><img src="test.jpg" style="display:none;" /></div>

How to change that with javascript, I know in css its:

.test img {display:block;}

but in javascript I only know this:

document.getElementById("test").style.display="block";

thats obviously the whole div tag , not the img.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T00:52:13+00:00Added an answer on May 27, 2026 at 12:52 am

    If you’re using an ID "test", you can do this.

    document.getElementById("test")
            .getElementsByTagName("img")[0].style.display="block";
    

    This uses getElementsByTagName which returns a collection of the images found. The [0] grabs the image at index 0 (the first image), and then applies the style.

    If you have a class "test", you can do this, but it won’t work in IE7 and below:

    var imgs = document.querySelectorAll(".test > img");
    
    for( var i = 0; i < imgs.length; i++ ) {
        imgs[i].style.display="block";
    }
    

    For the widest browser compatibility, you can do this:

    function getElementsByClassName( root, clss ) {
        var elems = document.getElementsByTagName('*'),
            result;
        clss = " " + clss + " ";
        for( var i = 0; i < elems.length; i++ ) {
            if( (" " + elems[ i ].className + " ").indexOf( clss ) > -1 ) {
                result.push( elems[i] );
            }
        }
        return result;
    }
    
    var tests = getElementsByClassName( document, "test" );
    
    for( var i = 0; i < tests.length; i++ ) {
        var img = tests[i].getElementsByTagName('img')[0];
        if( img ) {
             img.style.display="block";
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

the html code : <ul id=top10> <li class=test> <div class=first> <a href=#><img src=01.jpg></a> </div>
Is there a way to me do this? <img id=example src=anything.jpg title=something class=abc />
for example i have the markup <div> <img src=# alt=/> <img src=# alt=/> <img
I have a div: <div class=test id=someElement style=position: absolute></div> Is there any way to
i have some photos: <div class=photo> <a rel=example_group href=http://download.com/79.jpg><img class=edit_multimedia_img src=http://download.com/79.jpg></a> <a rel=example_group href=http://download.com/80.jpg><img
<div class=right> <div class=category-nav> <h2>test</h2> <ul class=item-list> <li><a href=#>example</a></li> <li><a href=#>example</a></li> <li><a href=#>example</a></li> <li><a
HTML: <div id=div_id><div class=div_class><p>test</p> </div> <div class=two> <p>asd</p></div> </div> CSS: #div_id p { color:red;
The CSS syntax highlighting in vim is not entirely optimal. For example: div.special_class stops
For example, i have this ImageViewer.ascx UserControl: <div class=ImageTumbnails> <asp:ListView ID=ImageList runat=server ItemPlaceholderID=ItemContainer> <LayoutTemplate>
Given the following HTML example... <div id='div1'>div one</div> <div id='div2'>div two</div> ...I found that

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.