не работает метод jquery
Можете объяснить, почему при нажатии на одну из 4 конопок, кнопки в появляющихся дивах не реагирует на методы jquery. Когда я нажимаю на одну из 4 кнопок, все хорошо обрабатывается, но когда я пробую нажимать на вновь появившиеяся кнопки ничего не происходит(P.S. сорри за корявый код, в css 2 раза объявлял свойства для класса task)
* {
vertical-align: baseline;
font-weight: inherit;
font-family: inherit;
font-style: inherit;
font-size: 100%;
border: 0 none;
outline: 0;
padding: 0;
margin: 0;
}/*Отмена стилей браузера*/
body{
height: 10000px;
}/*длина сайта(страницы)*/
textarea{
color:black;
border:1px solid red;
}/*настройка всех текстовых полей*/
.main_text{
margin-top: 20px;
margin-left: 20px;
}
.task{
top: 5px;
position: relative;
border:1px solid orange;
width: 95%;
margin-top: 20px;
margin-left: 20px;
height: auto;
margin-bottom: 30px;
}
/*Настройка поля с Основным заданием*/
.testtext1{
margin-top: 20px;
margin-left: 0;
}/* поле С Заданием 1*/
.first{
margin-bottom: -10px;
}
.icontest{
float: left;
width: 240px;
height:auto;
margin-top: 20px;
margin-left: 20px;
}/*Поле для всавляемого изображения*/
#inputfile{
margin-top: 20px;
margin-left: 0;
}/* Кнопка для добавления файлов*/
#areatext{
position: relative;
margin-top: 0px;
margin-left: 20px;
margin-bottom: 20px;
}/* Настройка поля для ввода от задания 1*/
.input_text{
margin-top: 30px;
}
.button{
margin-top: 20px;
margin-left: 20px;
padding-top: 155px;
padding-bottom: 158px;
padding-left: 105px;
padding-right: 105px;
background-color: #ffd694;
font-size: 50px;
color:#ff4d00;
border: 2px dashed orange;
}/* Настройка Кнопки ДОБАВИТЬ*/
.button:hover{
transition: all .5s;
transform: scale(1.1);
}/* Анимация Кнопки ДОБАВИТЬ*/
.add{
margin-bottom: 100px;
}
#radio{
margin-top: 0;
margin-left: 0;
}/* Настройка радио кнопок*/
.button_radio
{
margin-top: 30px;
float: left;
margin-right: 10px;
}
#check{
position: relative;
margin-top: 0;
margin-left: 0;
}/* Настройка чек боксов*/
.button_checkbox{
margin-top: 30px;
float: left;
margin-right: 10px;
}
#inp{
position: relative;
margin-top: 20px;
margin-left: 0;
margin-bottom: 20px;
}/* Настройка поля для ввода от задания 3*/
#inp input{
border: 1px solid red;
width: 240px;
}/* Настройка поля для ввода от задания 3*/
.add_button_answer{
position: relative;
margin-top: 0;
margin-left: 0;
padding-top: 0;
padding-bottom: 0;
padding-left: 109px;
padding-right: 109px;
background-color: #ffd694;
font-size: 30px;
color:#ff4d00;
border: 2px dashed orange;
margin-bottom: 0;
}
.add_button_answer:hover{
transition: all .5s;
transform: scale(1.1);
}/* Анимация Кнопки ДОБАВИТЬ*/
#footer{display: none;
margin-top: 10000px;
}/* футер*/
.task{
display:none;
}
* {
vertical-align: baseline;
font-weight: inherit;
font-family: inherit;
font-style: inherit;
font-size: 100%;
border: 0 none;
outline: 0;
padding: 0;
margin: 0;
}
body{
position: relative;
padding-bottom: 60px;
box-sizing: border-box;
}
#menu_bg {
position: absolute;
top: 61px;
width: 100%;
height: 360px;
margin:0 auto;
opacity: 1;
}
#menu_bg:hover{
opacity: 0.9;
}
.text_mainbg{
position: absolute;
font-size: 30px;
color: white;
margin-top: 200px;
margin-left: 40%;
margin-right: 40%;
background-color:black;
border-radius: 10%;
padding: 2px;
}
#menu_bg #logo{
margin-top: 90px;
margin-left: 45%;
position: absolute;
width: 100px;
height: 100px;
border: 1px solid red;
border-radius: 50%;
background-color: black;
}
#nav_menu{
position: fixed;
width: 100%;
height: 60px;
border:1px solid red;
background-color: orange
}
#main_content{
position: absolute;
top: 510px;
margin-left: 15%;
margin-right: 15%;
width: 70%;
height: 700px;
border: 1px solid red;
}
#menu1 ul li{
padding: 20px;
/*margin-right: 20px;*/
}
#menu1 ul li, #menu1 ul{
display: inline-block;
}
#menu1 ul{
position: absolute;
margin: 0;
padding: 0;
/*background-color: orange;*/
}
#menu1 ul ul{
display: none;
position: absolute;
background-color: white;
}
#menu1 ul > li:hover{
background-color: darkorange;
}
#menu1 ul a{
color: black;
text-decoration: none;
}
#menu1 ul ul a{
color: black;
text-decoration: none;
text-align: left;
}
#menu1 li:hover ul{
display: block;
top: 60px;
margin-left: -20px;
}
#menu1 li:hover li{
display: block;
}
#menu1 ul li a{
font-size: 18px;
}
#menu1 ul li ul li{
margin: 0;
}
#nav_menu .profile{
text-align: right;
margin-top: 20px;
margin-right: 10px;
}
#nav_menu .profile a{
font-size: 19px;
text-decoration: none;
color: black;
padding:20px;
}
#nav_menu .profile a:hover{
background-color: darkorange;
background-size:
}
#footer{
top: 1200px;
position: relative;
width: 100%;
height: 80px;
background-color: black;
bottom: 0;
}
#footer .text {
color: white;
font-size: 20px;
top: 40px;
padding: 10px;
}
#right_block{
top:550px;
position: absolute;
margin-left: 0.5%;
width: 14%;
height: 600px;
border:1px solid red;
}
#left_block{
top:550px;
margin-left: 85.5%;
position: absolute;
margin-right: 0.5%;
width: 14%;
height: 600px;
border:1px solid red;
}
#plus_inform{
position: absolute;
top: 450px;
width: 90%;
margin-left: 5%;
height: 40px;
border: 1px solid red;
background-color: orange;
}
.slider{
position: absolute;
top: 70px;
width: 99.2%;
height: 360px;
overflow: hidden;
border: 5px solid orange;
}
.navigation{
position: absolute;
bottom: 16px;
left: 50%;
transform: translateX(-50%);
display: flex;
}
.bar{
height: 8px;
width: 30px;
margin: 6px;
cursor: pointer;
background-color: red;
opacity: 0.7;
border-radius: 10px;
transition: all .4s ease;
}
.bar:hover{
opacity: 0.9;
transform: scale(2);
}
input[name='r']{
position: absolute;
visibility: hidden;
}
.slides{
width: 400%;
height: 100%;
display: flex;
}
.slide{
width: 25%;
transition: all .6s ease;
}
.slide img{
width: 100%;
height: 100%;
}
#r1:checked ~ .s1{
margin-left: 0;
}
#r2:checked ~ .s1{
margin-left: -25%;
}
#r3:checked ~ .s1{
margin-left: -50%;
}
#r4:checked ~ .s1{
margin-left: -75%;
}
#menu1 ul li {
border-right: 2px solid red;
padding-left: 20px;
}
#menu1 ul li a{
margin-left: -10px;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<head>
<meta http-equiv="Cache-Control" content="no-cache" charset="UTF-8">
<link rel="stylesheet" href="style/Register.css?123" type="text/css">
<link rel="stylesheet" href="style/cssfortest.css?123" type="text/css">
<!--<script type="text/javascript" src="jquery.js"></script>-->
<script type="text/javascript">
$(document).ready(function(){
$('#form_1').click(function(){
$('.textarea_template:hidden').clone().insertBefore('#form_handler').slideDown(1000);
});
$('#form_2').click(function(){
$('.radiobutton_template:hidden').clone().insertBefore('#form_handler').slideDown(1000);
});
$('#form_3').click(function(){
$('.checkboxbutton_template:hidden').clone().insertBefore('#form_handler').slideDown(1000);
});
$('#form_4').click(function(){
$('.input_template:hidden').clone().insertBefore('#form_handler').slideDown(1000);
});
$('.button').click(function(){
$(this).slideUp(1000);
});
});
</script>
</head>
<body>
<div id="page">
<div id="main_content"><!-- Основной див сайта -->
<form action="">
<div id="form_handler">
<input type="button" value="1 форма" id="form_1">
<input type="button" value="2 форма" id="form_2">
<input type="button" value="3 форма" id="form_3">
<input type="button" value="4 форма" id="form_4">
</div>
<div class="task textarea_template">
<textarea class="main_text" cols="110" rows="3" style="resize:none" placeholder="">
</textarea><!-- Общее задание -->
<div class="icontest">
<img id="uploadPreview" style="width:240px; height: 240px;" />
<input id="inputfile" type="file" name="myPhoto" onchange="PreviewImage();" accept="image/*" /><!-- Вставить изображение -->
<textarea class="testtext1 first" id="text" name="" id="" cols="30" rows="3" style="resize:none" placeholder="">
</textarea><!-- задание1 -->
</div>
<input type="button" class="button" value="+"><!-- Кнопка добавить -->
<div id="areatext">
<textarea name="" id="" cols="110" rows="3" style="resize:none">
</textarea><!-- Развернутый ответ -->
</div>
</div>
<div class="task radiobutton_template">
<textarea class="main_text" cols="110" rows="3" style="resize:none" placeholder="">
</textarea><!-- Общее задание -->
<div class="icontest ">
<img id="uploadPreview" style="width:240px; height: 240px;" />
<input id="inputfile" type="file" name="myPhoto" onchange="PreviewImage();" accept="image/*" /><!-- Вставить изображение -->
<textarea class="testtext1" id="text" name="" id="" cols="32" rows="3" style="resize:none" placeholder="">
</textarea><!-- задание1 -->
</div>
<input type="button" class="button add" value="+"><!-- Кнопка добавить -->
<div id="radio">
<input name="" type="radio" value="" class="button_radio"> <!-- радио кнопка -->
<textarea class="input_text" id="text" name="" id="" cols="28" rows="1" style="resize:none" placeholder="">
</textarea><!-- задание1 -->
</div>
<input type="button" class="add_button_answer" value="+"><!-- Кнопка добавить -->
</div>
<div class="task checkboxbutton_template">
<textarea class="main_text" cols="110" rows="3" style="resize:none" placeholder="">
</textarea><!-- Общее задание -->
<div class="icontest">
<img id="uploadPreview" style="width:240px; height: 240px;" />
<input id="inputfile" type="file" name="myPhoto" onchange="PreviewImage();" accept="image/*" /><!-- Вставить изображение -->
<textarea class="testtext1" id="text" name="" id="" cols="32" rows="3" style="resize:none" placeholder="">
</textarea><!-- задание1 -->
</div>
<input type="button" class="button add" value="+"><!-- Кнопка добавить -->
<div id="check">
<input type="checkbox" name="a" value="" class="button_checkbox" > <!-- чекбокс -->
<textarea class="input_text" id="text" name="" id="" cols="28" rows="1" style="resize:none" placeholder="">
</textarea><!-- задание1 -->
</div>
<input type="button" class="add_button_answer" value="+"><!-- Кнопка добавить -->
</div>
<div class="task input_template">
<textarea class="main_text" cols="110" rows="3" style="resize:none" placeholder="">
</textarea><!-- Общее задание -->
<div class="icontest">
<img id="uploadPreview" style="width:240px; height: 240px;" />
<input id="inputfile" type="file" name="myPhoto" onchange="PreviewImage();" accept="image/*" /><!-- Вставить изображение -->
<textarea class="testtext1" id="text" name="" id="" cols="32" rows="3" style="resize:none" placeholder="поздровляю">
</textarea><!-- задание1 -->
</div>
<input type="button" class="button add" value="+"><!-- Кнопка добавить -->
<div id="inp">
<input type="text" name="a" value=""> <!-- Поле для ввода ответа -->
</div>
</div>
</div>
<script type="text/javascript">
function PreviewImage() {
var oFReader = new FileReader();
oFReader.readAsDataURL(document.getElementById("inputfile").files[0]);
oFReader.onload = function (oFREvent) {
document.getElementById("uploadPreview").src = oFREvent.target.result;
};
};
</script><!-- Превью Изображения на сайте -->
</form>
</div>
Ответы (1 шт):
Автор решения: Максим Ларченко
→ Ссылка
нашел решение, просто плохо понимал, как работает clone(), у меня просто не работал обработчик событий для дочерних элементов. Нашел, что достаточно в параметры этой функции передать deepWithDataAndEvents