I wonder if there is any way to load a jquery before the page is loaded

Asked

Viewed 90 times

-2

-I’m testing to load the rest just put an id on the body to see if it would

 <script type="text/javascript" >
 $(document).ready(function() {

 $("#body").load(function(){

          var tip = $(this).find("#sessaocad").val();

         if (tip == "Banco"){
           $("#tipousu").css("display","none"); 
            $("#tipousulbl").css("display","none");

           $("#tiposang").css("display","none");
           $("#tiposanglbl").css("display","none");

           $("#rg").css("display","none");  

           $("#cnpj").css("display","block");  
       } 
       if (tip == "Pessoa"){
         //MOSTRA 
           $("#tipousu").css("display","block"); 
           $("#tipousulbl").css("display","block");

           $("#tiposang").css("display","block");
           $("#tiposanglbl").css("display","block");

           $("#rg").css("display","block");  

           $("#cnpj").css("display","none");  
       }
       });
      });
    </script> 
  • What you got as a result?

  • nothing, the page loads but depending on my login type it would have to be changed but I think as the function is only called after the page load no changes is made, so I wonder if there is any way that jquery can be executed before the page is loaded

1 answer

0

The ready() function as you can check in documentation in other words it only executes what is inside it after loading its selector is safely "fully loaded" as you are using $(Document) as selector it will only run after loading everything.

a possible solution would be to create your rule outside the

... $(Document). ready(Function() { ...

a tip to organize your code use files . js (external) instead of writing your codes inside the page.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.