2017-02-11 6 views
0
<!DOCTYPE html> 
<html> 
<head> 
<script  src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script> 
<script> 
$(document).ready(function(){ 
$("button").click(function(){ 
$("p").toggle(); 
}); 
}); 
</script> 
</head> 
<body> 

<button style="width:80%;height:35px;">Toggle between hiding and showing the  paragraphs</button> 

<p>This is a paragraph with little content.</p> 
<p>This is another small paragraph.</p> 
</body> 
</html> 

ce code cacher et afficher la div sur un clic d'un bouton. ce code fonctionne très bien ... mais je veux que div soit caché en premier. il sera montré après avoir cliqué.Masquer et afficher d'une div sur un clic d'un bouton

+1

pourquoi vous avez marqué sql-server, base de données, hébergement web – kritikaTalwar

+0

style add = "display: none;" à l'étiquette qui devrait être initialement caché – olk

+0

olk .. merci beaucoup ... –

Répondre

1

affichage de style Ajouter: aucun dans la balise p

<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script> 
<script> 
    $(document).ready(function(){ 
     $("button").click(function(){ 
     $("p").toggle(); 
     }); 
    }); 
</script> 
<style> 
     p{ 
      display:none; 
     } 
    </style> 
</head> 
<body> 

    <button style="width:80%;height:35px;">Toggle between hiding and showing the paragraphs</button> 

    <p>This is a paragraph with little content.</p> 
    <p>This is another small paragraph.</p> 
</body>