Форум программистов, компьютерный форум, киберфорум
jQuery
Войти
Регистрация
Восстановить пароль
Блоги Сообщество Поиск Заказать работу  
 
Рейтинг 4.71/7: Рейтинг темы: голосов - 7, средняя оценка - 4.71
0 / 0 / 0
Регистрация: 02.10.2018
Сообщений: 3

По нажатию на стрелку прятать/выводить то, что было в <div>

09.10.2018, 22:38. Показов 1454. Ответов 1
Метки нет (Все метки)

Студворк — интернет-сервис помощи студентам
Помогите пожалуйста,
С предыдущим вопросом все понял (спасибо пользователю Mr_Sergo), теперь в продолжении моей задачки нужно, чтобы по нажатию на стрелочку блок спрятался и выводился при повторном нажатии. Исключение в этой задачке то, что таких блоков может быть много - тут и идентифицировать с id не поможет т.к. он должен быть уникальным, и к классу class не присвоишь, иначе обратимся ко всем блокам.

Тут походу только с помощью parent() next() или parents() обратиться к определенному блоку.

Лайк диз:

JavaScript
1
2
3
4
5
6
7
8
9
$('.hiden').click(function(){
    var slide = $('.box-job h3');
    if (slide.is(':visible')){
        slide.hide();
    }
    else {
        slide.show();
    }
});
html код:
HTML5
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
44
45
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Список дел</title>
    <link rel="stylesheet" href="style.css">
    <script src="jquery-3.3.1.min.js"></script>
    <script src="script.js"></script>
    
</head>
<body>
    <main>
        <section class="left">
            <h1>Список дел:</h1>
            <article id="listJob">
                <div class="box-job">
                    <h2>
                        Иван
                        <img src="https://www.cyberforum.ru/images/clear-button.png" alt="" onclick="$(this).parent().parent().remove()">
                        <div class="arrow">
                            <img src="https://www.cyberforum.ru/images/arrow.png" alt="" class="hiden">
                        </div>
                    </h2>
                    <h3>123</h3>
                </div>      
            </article>
            
        
        </section>
        <section class="right">
            <h1>Добавить новое дело:</h1>
            <article class="addJob">
                <form action="" method="post">
                    <p>* Название</p>
                    <input type="text" name="name" required="required" id="input_h2" >
                    <p id="opisanie">* Описание</p>
                    <textarea name="description" id="input_p" cols="30" rows="10" required="required"></textarea>
                    <input type="submit" value="Добавить дело" id="add">
                </form>
            </article>
            <h2></h2>
        </section>
    </main>
</body>
</html>
css код:
CSS
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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
body, html {
    padding: 0;
    margin: 0;
    min-width: 1000px;
    font-family: Arial;
}
 
body {
    background-color: #f5f5f5;
}
 
main {
    
    width: 960px;
    margin: 65px auto 0px auto;
    position: relative;
}
h1{
    font-size: 21px;
    font-weight: normal;
    margin:0;
}
 
h2 {
    font-size: 16px;
    font-weight: normal;
    margin-top: 30px;
    margin-bottom: 0px;
    padding: 20px;
    border-bottom: 1px solid #f7f7f7;
    background-color: white;
}
h3 {
    font-size: 16px;
    font-weight: normal;
    margin: 0px;
    padding: 20px;
    background-color: white;
    
}
 
p {
    font-size: 14px;
    color:#8993ad;
    padding:50px 0 11px 40px;
    margin: 30px 0 0 0 ;
}
 
 
 
input {
    margin: 0 40px;
    padding: 15px 0 15px 13px;
    font-size: 16px;
    width: 373px;
}
    #add {
        margin: 30px 0px 55px 40px;
        padding: 20px 55px;
        color: white;
        background-color: #2174fd;
        width: 225px;
        border: 0;
    }
 
textarea {
    font-family: Arial;
    margin: 0 40px;
    padding: 15px 0 15px 13px;
    font-size: 16px;
    width: 373px;
}
 
#listJob {
    
    width: 470px;
    position: relative;
 
}
 
.right {
    top: 0px;
    width: 470px;
    float: right;
    
 
}
.left {
    position: absolute;
    width: 470px;
    margin-right: 20px;
}
.addJob {
    background-color: white;
    
    
}
 
img {
    margin-left: 20px;
}
 
.arrow {
    float: right;
}
скрипт:
JavaScript
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
$(function(){
$('#add').click(function () {
    var inp =
        $(
        '<div class="box-job">' +
            '<h2>' + $('#input_h2').val() + 
                '<img src="https://www.cyberforum.ru/images/clear-button.png" alt="" onclick="$(this).parent().parent().remove()">' + // тут обращаемся к родителю родителя (class="box-job") и удаляем его и все что он содержит
                '<div class="arrow">' +
                '<img src="https://www.cyberforum.ru/images/arrow.png" alt="" class="hiden">' +
                '</div>' +
            '</h2>' +
            '<h3>'+ $('#input_p').val() + '</h3>'+
        '<div>'
    );
    $('#listJob').prepend(inp);
 
    $('#input_h2').val('').focus();
    $('#input_p').val('').focus();
 
    return false;
});
$('.hiden').click(function(){
    var slide = $('.box-job h3');
    if (slide.is(':visible')){
        slide.hide();
    }
    else {
        slide.show();
    }
});
});
Очень надеюсь на вашу помощь.

P.s. Я тут новичок, недавно зарегистрировался. Если я ранее уже создавал тему, то надо было писать там и дальше? Подскажите плиз.
0
Лучшие ответы (1)
Programming
Эксперт
39485 / 9562 / 3019
Регистрация: 12.04.2006
Сообщений: 41,671
Блог
09.10.2018, 22:38
Ответы с готовыми решениями:

Прятать формы по нажатию на крестик
Из одной формы (form1)по выбору элемента списка(listbox) вызывается другая(form2), при вызове(f.Show()) form1 не закрывается. f определена...

Прятать блоки div
В общем, у меня на странице находится около 50 блоков вот такого содержания: &lt;div class=&quot;container&quot;&gt; Нужная...

С помощью прерываний выводить мышь на экран а потом прятать
Задание:Написать программу которая будет с помощью прерываний выводить мышь на экран а потом прятать Мое решение(неверное). uses...

1
Эксперт JS
2037 / 1096 / 409
Регистрация: 29.04.2016
Сообщений: 2,625
10.10.2018, 05:46
Лучший ответ Сообщение было отмечено Mr_Sergo как решение

Решение

Menskiy,

Демка
HTML5
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
<main>
    <section class="left">
        <h1>Список дел:</h1>
        <article id="listJob">
            <div class="arrow" onclick="rollUp(event)"></div>
            <div class="box-job">
                <h2>
                    Иван
                    <img src="http://harinama-mantra.org/images/000%20%D0%BA%D0%BD%D0%BE%D0%BF%D0%BA%D0%B0%20%D0%B7%D0%B0%D0%BA%D1%80%D1%8B%D1%82%D1%8C-u1038-fr.png" alt="" onclick="remove($(this),event)" class="del">
                </h2>
                <h3>123</h3>
            </div>      
        </article>
    </section>
    <section class="right">
        <h1>Добавить новое дело:</h1>
        <article class="addJob">
            <form action="" method="post">
                <p>* Название</p>
                <input type="text" name="name" id="input_h2" required="required">
                <p id="opisanie">* Описание</p>
                <textarea name="description" id="input_p" cols="30" rows="10" required="required"></textarea>
                <input type="submit" value="Добавить дело" id="add">
            </form>
        </article>
        <h2></h2>
    </section>
</main>
JavaScript
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
$('#add').click(function(){
    if($('#input_h2').val() !=='' && $('#input_p') !== ''){
        var inp =
            $('<div class="arrow" onclick="rollUp(event)"></div>' +
            '<div class="box-job">' +
                '<h2>' + $('#input_h2').val() +
                    '<img src="http://harinama-mantra.org/images/000%20%D0%BA%D0%BD%D0%BE%D0%BF%D0%BA%D0%B0%20%D0%B7%D0%B0%D0%BA%D1%80%D1%8B%D1%82%D1%8C-u1038-fr.png" alt="" onclick="remove($(this),event)" class="del">' +
                '</h2>' +
                '<h3>'+$('#input_p').val()+'</h3>' +
            '</div>'
        );
        $('#listJob').prepend(inp);
    }
 
    $('#input_h2').val('').focus();
    $('#input_p').val('').focus();
 
    return false;
});
 
function remove(x,e){
    var ind = $('.del').index(e.target);
    x.parent().parent().remove();
    $('.arrow').eq(ind).remove();
}
 
function rollUp(e){
    var ind = $('.arrow').index(e.target);
 
    if($('.box-job').eq(ind).height() > 0){
        $('.box-job').eq(ind).css('height','0px');
        $('.arrow').eq(ind).css('transform','scale(1, -1)');
    }
    else{
        $('.box-job').eq(ind).css('height','fit-content');
        $('.arrow').eq(ind).css('transform','scale(1, 1)');
    }
}
CSS
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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
body, html {
    padding: 0;
    margin: 0;
    min-width: 1000px;
    font-family: Arial;
}
 
body {
    background-color: #f5f5f5;
}
 
main {
    
    width: 960px;
    margin: 65px auto 0px auto;
    position: relative;
}
h1{
    font-size: 21px;
    font-weight: normal;
    margin:0;
}
 
h2 {
    height: fit-content;
    font-size: 16px;
    font-weight: normal;
    /* margin-top: 30px; */
    margin-bottom: 0px;
    padding: 20px;
    border-bottom: 1px solid #f7f7f7;
    background-color: white;
    word-break: break-all;
}
h3 {
    font-size: 16px;
    font-weight: normal;
    margin: 0px;
    padding: 20px;
    background-color: white;
    word-break: break-all;
}
 
p {
    font-size: 14px;
    color:#8993ad;
    padding:50px 0 11px 40px;
    margin: 30px 0 0 0 ;
}
 
 
 
input {
    margin: 0 40px;
    padding: 15px 0 15px 13px;
    font-size: 16px;
    width: 373px;
}
    #add {
        margin: 30px 0px 55px 40px;
        padding: 20px 55px;
        color: white;
        background-color: #2174fd;
        width: 225px;
        border: 0;
    }
 
textarea {
    font-family: Arial;
    margin: 0 40px;
    padding: 15px 0 15px 13px;
    font-size: 16px;
    width: 373px;
}
 
#listJob {
    width: 470px;
    height: fit-content;
    position: relative;
}
 
.right {
    top: 0px;
    width: 470px;
    float: right;
    
 
}
.left {
    position: absolute;
    width: 470px;
    margin-right: 20px;
}
.addJob {
    background-color: white;
    
    
}
 
img {
    margin-left: 20px;
    width: 30px;
    float: right;
}
 
.arrow {
    width: 100%;
    height: 30px;
    background: #2174fd;
    background-image: url(http://confident-driver.ru/wp-content/uploads/2018/05/on-white-arrow-symbols-icons-2226.png);
    background-repeat: no-repeat;
    background-size: 20px;
    background-position: right;
    cursor: pointer;
    margin: 20px 0px 0px 0px;
}
 
.box-job{
    overflow: hidden;
    height: fit-content;
}
Добавлено через 1 час 15 минут
Menskiy,

Хотя вот так наверное будет получше: https://codepen.io/zlojnaxa/full/RepxZz/
HTML5
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
<main>
    <section class="left">
        <h1>Список дел:</h1>
        <article id="listJob">
            <div class="arrow" onclick="rollUp(event)"></div>
            <div class="box-job">
                <img src="http://harinama-mantra.org/images/000%20%D0%BA%D0%BD%D0%BE%D0%BF%D0%BA%D0%B0%20%D0%B7%D0%B0%D0%BA%D1%80%D1%8B%D1%82%D1%8C-u1038-fr.png" alt="" onclick="remove($(this),event)" class="del">
                <h2>
                    Иван
                    
                </h2>
                <h3>123</h3>
            </div>      
        </article>
    </section>
    <section class="right">
        <h1>Добавить новое дело:</h1>
        <article class="addJob">
            <form action="" method="post">
                <p>* Название</p>
                <input type="text" name="name" id="input_h2" required="required">
                <p id="opisanie">* Описание</p>
                <textarea name="description" id="input_p" cols="30" rows="10" required="required"></textarea>
                <input type="submit" value="Добавить дело" id="add">
            </form>
        </article>
        <h2></h2>
    </section>
</main>
JavaScript
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
$('#add').click(function(){
    if($('#input_h2').val() !=='' && $('#input_p') !== ''){
        var inp =
            $('<div class="arrow" onclick="rollUp(event)"></div>' +
            '<div class="box-job">' +
                '<img src="http://harinama-mantra.org/images/000%20%D0%BA%D0%BD%D0%BE%D0%BF%D0%BA%D0%B0%20%D0%B7%D0%B0%D0%BA%D1%80%D1%8B%D1%82%D1%8C-u1038-fr.png" alt="" onclick="remove($(this),event)" class="del">' +
                '<h2>' + $('#input_h2').val() + '</h2>' +
                '<h3>'+$('#input_p').val()+'</h3>' +
            '</div>'
        );
        $('#listJob').prepend(inp);
    }
 
    $('#input_h2').val('').focus();
    $('#input_p').val('').focus();
 
    return false;
});
 
function remove(x,e){
    var ind = $('.del').index(e.target);
    x.parent().remove();
    $('.arrow').eq(ind).remove();
}
 
function rollUp(e){
    var ind = $('.arrow').index(e.target);
 
    if($('.box-job').eq(ind).height() > 0){
        $('.box-job').eq(ind).css('height','0px');
        $('.arrow').eq(ind).css('transform','scale(1, -1)');
    }
    else{
        $('.box-job').eq(ind).css('height','fit-content');
        $('.arrow').eq(ind).css('transform','scale(1, 1)');
    }
}
CSS
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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
body, html {
    padding: 0;
    margin: 0;
    min-width: 1000px;
    font-family: Arial;
}
 
body {
    background-color: #f5f5f5;
}
 
main {
    
    width: 960px;
    margin: 65px auto 0px auto;
    position: relative;
}
h1{
    font-size: 21px;
    font-weight: normal;
    margin:0;
}
 
h2 {
    height: fit-content;
    font-size: 16px;
    font-weight: normal;
    /* margin-top: 30px; */
    margin-bottom: 0px;
    padding: 20px;
    border-bottom: 1px solid #f7f7f7;
    background-color: white;
    word-break: break-all;
}
h3 {
    font-size: 16px;
    font-weight: normal;
    margin: 0px;
    padding: 20px;
    background-color: white;
    word-break: break-all;
}
 
p {
    font-size: 14px;
    color:#8993ad;
    padding:50px 0 11px 40px;
    margin: 30px 0 0 0 ;
}
 
 
 
input {
    margin: 0 40px;
    padding: 15px 0 15px 13px;
    font-size: 16px;
    width: 373px;
}
    #add {
        margin: 30px 0px 55px 40px;
        padding: 20px 55px;
        color: white;
        background-color: #2174fd;
        width: 225px;
        border: 0;
    }
 
textarea {
    font-family: Arial;
    margin: 0 40px;
    padding: 15px 0 15px 13px;
    font-size: 16px;
    width: 373px;
}
 
#listJob {
    width: 470px;
    height: fit-content;
    position: relative;
}
 
.right {
    top: 0px;
    width: 470px;
    float: right;
    
 
}
.left {
    position: absolute;
    width: 470px;
    margin-right: 20px;
}
.addJob {
    background-color: white;
    
    
}
 
img {
    margin-left: 20px;
    margin-top: 15px;
    width: 30px;
    float: right;
}
 
.arrow {
    width: 100%;
    height: 30px;
    background: #2174fd;
    background-image: url(http://confident-driver.ru/wp-content/uploads/2018/05/on-white-arrow-symbols-icons-2226.png);
    background-repeat: no-repeat;
    background-size: 20px;
    background-position: right;
    cursor: pointer;
    margin: 20px 0px 0px 0px;
}
 
.box-job{
    overflow: hidden;
    height: fit-content;
}
1
Надоела реклама? Зарегистрируйтесь и она исчезнет полностью.
inter-admin
Эксперт
29715 / 6470 / 2152
Регистрация: 06.03.2009
Сообщений: 28,500
Блог
10.10.2018, 05:46
Помогаю со студенческими работами здесь

Прятать <div> по значению checkbox
Добрый день! В js не силён, начинаю с азов. Есть такая задача, прошу помощи - Есть 2 массива. В первый собираются значения...

ToggleCLASS - прятать один div при клике в область другого
Как сделать так, чтоб если тыкаю в место определённого дива (назовём его главным) убирался другой див (назовём его панелью). Просто...

Нужно вставить программно в эксель по нажатию на кнопку символ стрелку вверх
Помогите, пожалуйста, вставить программно в эксель по нажатию на кнопку символ стрелку вверх. номер символа 24. Что пробовал: ...

Как изменить значения div в css, чтобы расстояния между блоками div не было?
Приветствую! Не могу решить такую задачу. Имеется общая обертка div (wrap). Внутри div-wrap имеется 3 div - header, content и foot. При...

Как в Visual Studio 2005 реализовать установку курсора в текстовое поле по нажатию на стрелку
Здравствуйте. В Visual Studio 2005 реализовал установку курсора в текстовое поле по нажатию на стрелку вверх и стрелку вниз на...


Искать еще темы с ответами

Или воспользуйтесь поиском по форуму:
2
Ответ Создать тему
Новые блоги и статьи
Воспроизведение звукового файла с помощью SDL3_mixer при касании экрана Android
8Observer8 26.01.2026
Содержание блога SDL3_mixer - это библиотека я для воспроизведения аудио. В отличие от инструкции по добавлению текста код по проигрыванию звука уже содержится в шаблоне примера. Нужно только. . .
Установка Android SDK, NDK, JDK, CMake и т.д.
8Observer8 25.01.2026
Содержание блога Перейдите по ссылке: https:/ / developer. android. com/ studio и в самом низу страницы кликните по архиву "commandlinetools-win-xxxxxx_latest. zip" Извлеките архив и вы увидите. . .
Вывод текста со шрифтом TTF на Android с помощью библиотеки SDL3_ttf
8Observer8 25.01.2026
Содержание блога Если у вас не установлены Android SDK, NDK, JDK, и т. д. то сделайте это по следующей инструкции: Установка Android SDK, NDK, JDK, CMake и т. д. Сборка примера Скачайте. . .
Использование SDL3-callbacks вместо функции main() на Android, Desktop и WebAssembly
8Observer8 24.01.2026
Содержание блога Если вы откроете примеры для начинающих на официальном репозитории SDL3 в папке: examples, то вы увидите, что все примеры используют следующие четыре обязательные функции, а. . .
моя боль
iceja 24.01.2026
Выложила интерполяцию кубическими сплайнами www. iceja. net REST сервисы временно не работают, только через Web. Написала за 56 рабочих часов этот сайт с нуля. При помощи perplexity. ai PRO , при. . .
Модель сукцессии микоризы
anaschu 24.01.2026
Решили писать научную статью с неким РОманом
http://iceja.net/ математические сервисы
iceja 20.01.2026
Обновила свой сайт http:/ / iceja. net/ , приделала Fast Fourier Transform экстраполяцию сигналов. Однако предсказывает далеко не каждый сигнал (см ограничения http:/ / iceja. net/ fourier/ docs ). Также. . .
http://iceja.net/ сервер решения полиномов
iceja 18.01.2026
Выкатила http:/ / iceja. net/ сервер решения полиномов (находит действительные корни полиномов методом Штурма). На сайте документация по API, но скажу прямо VPS слабенький и 200 000 полиномов. . .
КиберФорум - форум программистов, компьютерный форум, программирование
Powered by vBulletin
Copyright ©2000 - 2026, CyberForum.ru