Sorry die für noobish Frage, meine erste Website.Verstecken mehrere divs innerhalb eines div - JQuery
Ich möchte, dass, wenn das ".button" div angeklickt wird, alle divs innerhalb des ".container" -div ausgeblendet oder versteckt werden, aber es scheint nicht zu funktionieren. Ich würde es vorziehen, die js in einer separaten Datei zu halten.
HTML
<!DOCTYPE html>
<html>
<head>
<title>MAIN</title>
<link rel='stylesheet' type='text/css' href='style.css' />
<script type='text/javascript' src='script.js'> </script>
</head>
<body>
<div class="container">
<div class="top">
MENU
</div>
<div class="button">
^^^
</div>
</div>
</body>
CSS
.top {
/* Border */
border: 5px solid gray;
width: 100px;
background-color: black;
/*Positioning*/
margin-left: 25%;
margin-right: 25%;
top: 10px;
left: 0px;
position: absolute;
/*Text*/
text-align: center;
font-family: Arial;
font-weight: bold;
font-size: 20px;
color: white;
}
.container {
/*Border*/
border: 10px solid gray;
width: 200px;
height: 200px;
background-color: black;
/*Positioning*/
margin-left: auto;
margin-right: auto;
position: relative;
}
.button {
/*Border*/
border: 2px solid gray;
background-color: black;
width: 98%;
/*Positioning*/
margin-top: 90%;
margin-left: auto;
margin-right: auto;
/*Text*/
text-align: center;
font-family: Arial;
font-size: 15px;
color: white;
}
.button:hover {
color: red;
font-weight: bold;
}
JAVASCRIPT
$(document).ready(function() {
$('.button').click(function() {
$('.container').hide('fast');
});
});
'$ ('. Container'). Finden ('div'). Ausblenden ('fast');' verwenden Sie diese – guradio
so alle Inhalte innerhalb des Containers, aber nur diesen Container? Sie sind auch sicher, dass Sie alles ausblenden möchten, da der Knopf auch darin ist. –
Können Sie mit Alert testen ("irgendein Text"); zu sehen, dass das Click-Ereignis tatsächlich behandelt wird? – VinhNT