javascript - Click an Image to Reveal Content -


i have searched searched answer question can't seem find answer works me. i'm wanting image presents on page normal tag. want image clickable, , when clicked, content drop down below description of image, etc. then, when image clicked again, hide content.

my (beginner) javascript attempt looks this:

<script type="text/javascript" src="//code.jquery.com/jquery-1.9.1.js">  $(window).load(function(){ $(".header").click(function () {  $header = $(this); //getting next element $content = $header.next(); //open content needed - toggle slide- if visible, slide up, if not slidedown. $content.slidetoggle(500, function () {     //execute after slidetoggle done     //change text of header based on visibility of content div     $header.text(function () {         //change text based on condition         return $content.is(":visible") ? "collapse" : "expand";     }); });   

the html this:

    <div class="container"> <div class="header"><img src="placeholders/placeholder.jpg" width="500" height="333"></div> <div class="content" style="display: none;">     words should here. </div> 

any appreciated, , apologize if has been answered elsewhere. couldn't find it.

try html:

 <div class="container">     <div class="header"><img src="placeholders/placeholder.jpg" width="500" height="333"></div>     <div class="content" style="height: 0px;overflow:hidden;">         words should here.     </div> 

and script:

$(document).ready(function(){     $(".header").click(function () {          if($(".content").height() === 0){              $(".content").animate({height: "20px"}, 500);         }else{             $(".content").animate({height: "0px"}, 500);         }      }); }) 

on jsfiddle: https://jsfiddle.net/wef1o0b5/


Comments

Popular posts from this blog

java - Spring Data JPA: Why findOne(id) executing delete query internally? -

python - Mongodb How to add addtional information when aggregating? -

java - Incorrect order of records in M-M relationship in hibernate -