最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

jquery - How to hide a div on document ready, and then call it dynamically from Javascript? - Stack Overflow

programmeradmin6浏览0评论

I'm using this code to hide a div container where I'm placing text dynamically.

$(document).ready(function(){
     $(".slidingDiv").hide(); 
     $(".show_hide").show();

     $('.show_hide').click(function(){
         $(".slidingDiv").slideToggle();
     });
 });

The problem I have is that I want to trigger the show div from a javascript function instead of a predefined click event. I've found this example which mateches the function I want, but I'm not sure how to trigger it from javascript instead of a click function.

JSFiddle Here

I'm using this code to hide a div container where I'm placing text dynamically.

$(document).ready(function(){
     $(".slidingDiv").hide(); 
     $(".show_hide").show();

     $('.show_hide').click(function(){
         $(".slidingDiv").slideToggle();
     });
 });

The problem I have is that I want to trigger the show div from a javascript function instead of a predefined click event. I've found this example which mateches the function I want, but I'm not sure how to trigger it from javascript instead of a click function.

JSFiddle Here

Share Improve this question edited Mar 13, 2013 at 10:13 BenM 53.2k26 gold badges115 silver badges172 bronze badges asked Mar 13, 2013 at 10:10 blargblarg 3,89311 gold badges46 silver badges75 bronze badges 1
  • set-timeout and setTimeinterval is the function that will allow to call function after some periodic time set in it – Dipesh Parmar Commented Mar 13, 2013 at 10:13
Add a ment  | 

3 Answers 3

Reset to default 10

just hide the div using css

display:none;

.slidingDiv{
 display:none;
}

and show it when ever you want using

.show()

$(".slidingDiv").show();

edit:

after you question edit, you can always trigger the click event programatically like

function yourFunction(){
  $(".show_hide").click();
} 

At any point in your script you can call the jQuery object with your div's id/class and run the show() function. i.e.

var javascript = "cool";
var foo = "I'm doing stuff";
var bar = "And some more stuff";
if (javascript === "cool") 
    jQuery(".slidingDiv").show();
else 
    $(".slidingDiv").show();

         <script>
    $(document).ready(function(){
      $("input[type='file']").on("change", function () {
         if(this.files[0].size > 1000000) //file size less than 1MB { 
             {
          
                $("#fileAlert").show(); //calling a bootstrap 4 alert
             }
        
          $(this).val('');
         }
        });
    });
</script>

与本文相关的文章

发布评论

评论列表(0)

  1. 暂无评论