The task is probably simple, but in programming I am a hard lamer.


<div onclick="func()"> <div style="display:none;"></div> </div> 

It would be desirable that by clicking on a div with a function, the display property of the internal div changes. Do not laugh :) I tried through this ... but it changes the property of the external div ... but I want it at the internal one. Is it all real?

At the extreme, you can assign a class to an internal div.

  • By the way @ustal getElementsByClassName does not work in IE <9 I wrote a universal function in your question [How to set a div with the same class display property: none] ( hashcode.ru/questions/113177 / ... "How to set a div with the same class display property: none ") - Rules

1 answer 1

 <script type="text/javascript"> function func(el){ el.firstElementChild.style.display = 'block'; } </script> <div onclick="func(this)">123 <div style="display:none;">456</div> </div> 
  • firstElementChild is funny :) and secondElementChild happens? or how to act in such cases? In general, MEGA-thanks :) - Nuboyd
  • firstElementChild is the first child; lastElementChild - the last child; nextElementSibling - the next elements; previousElementSibling - previous elements; childElementCount - the number of children. - Deonis
  • @ustal, el1.childNodes[1] - ReinRaus
  • and the last question is something like for all divs with class = "primer" on the page, set the display property: none; ... and I am happy :) - Nuboyd
  • one
    @ReinRaus, don't argue with me . - karmadro4