jquery - Javascript not following step by step instruction -


this html

$(function(){      $(".button1").on("click",function(){          $(".img").css("display","block");          $(".bord").append('<div class="test1">11111111</div>');          $(".img").css("display","none");      });  });
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script>             <div class="parent">       <div class="button1">button1</div>       <div class="button2">button2</div>  </div>                <div class="bord">       <img src="http://www.mtlexs.com/images/reload.gif" class="img" style="display: none;">   </div>                                   

here write code , when button1 click show image, display text, hide image . here image not showing

then change code show image , display text , , working

 $(function(){         $(".button1").on("click",function(){               $(".img").css("display","block");               $(".bord").append('<div class="test1">11111111</div>');         });      });
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script>  <div class="parent">        <div class="button1">button1</div>        <div class="button2">button2</div>  </div>                    <div class="bord">        <img src="http://www.mtlexs.com/images/reload.gif" class="img" style="display: none;">  </div>

so problem in first code ?

i need show image->show text-->hide image

please check .

you updating value of display quicky. if add timeout see image showing hidding.

the change not directly rendered (see @maximus's answer)

add timeout , work want

$(function() {      $(".button1").on("click", function() {        $(".img").css("display", "block");      $(".bord").append('<div class="test1">11111111</div>');      settimeout(        function() {              $(".img").css("display", "none");        }, 2000);    });    });
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script>    <div class="parent">    <div class="button1">button1</div>    <div class="button2">button2</div>  </div>    <div class="bord">    <img src="http://www.mtlexs.com/images/reload.gif" class="img" style="display: none;">  </div>


Comments

Popular posts from this blog

php - How to add and update images or image url in Volusion using Volusion API -

javascript - IE9 error '$'is not defined -