1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43
| <!DOCTYPE html>
<html lang="fr">
<head>
<meta charset="utf-8">
<title>Afficher/cacher des blocs</title>
<script src="//code.jquery.com/jquery-1.11.2.js"></script>
<script>
$(function(){
$(".reserveraction").on('click',function()
{
var that = $(this);
$(".cacherreserver").each(function()
{
if($(this).data("id") == that.data("id")) {$(this).fadeToggle( "fast", "linear" )}
})
});
});
</script>
<style type="text/css">
.reserveraction
{
text-decoration:underline;
cursor:pointer;
display:inline-block;/* sert juste pour définir une marge entre les éléments en ligne*/
margin-right:2em;
}
.cacherreserver
{
display:none;
border:1px solid black;
}
</style>
</head>
<body>
<span data-id="2" class="reserveraction"> pour faire apparaître ou disparaître 2</span>
<span data-id="3" class="reserveraction"> pour faire apparaître ou disparaître 3</span>
<span data-id="4" class="reserveraction"> pour faire apparaître ou disparaître 4</span>
<div data-id="2" class="cacherreserver">2</div>
<div data-id="3" class="cacherreserver">3</div>
<div data-id="4" class="cacherreserver">4</div>
</body>
</html> |