Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Hw 1(dom) #853

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
58 changes: 52 additions & 6 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

<body>
<div class="container">
<ul class="comments">
<ul id="comment-list" class="comments">
<li class="comment">
<div class="comment-header">
<div>Глеб Фокин</div>
Expand All @@ -26,6 +26,7 @@
</div>
</div>
</li>

<li class="comment">
<div class="comment-header">
<div>Варвара Н.</div>
Expand All @@ -43,14 +44,22 @@
</div>
</div>
</li>

<li>
<div id="name-output"></div>
<div id="comment-output"></div>
</li>
</ul>

<div class="add-form">
<input
id="name-input"
type="text"
class="add-form-name"
placeholder="Введите ваше имя"
/>
<textarea
id="comment-input"
type="textarea"
class="add-form-text"
placeholder="Введите ваш коментарий"
Expand All @@ -61,11 +70,48 @@
</div>
</div>
</div>
</body>

<script>
"use strict";
// Код писать здесь
console.log("It works!");

<script>
document.addEventListener("DOMContentLoaded", function() {
const addButton = document.querySelector('.add-form-button');

addButton.addEventListener('click', function() {
const nameInput = document.getElementById('name-input').value;
const commentInput = document.getElementById('comment-input').value;

createComment(nameInput, commentInput);
});
});

function createComment(commenterName, commentText) {
if (!commenterName || !commentText) {
alert('Введите имя и комментарий');
return;
}

const parentList = document.getElementById('comment-list');

const newComment = document.createElement('li');
newComment.className = 'comment';

const commentHeader = document.createElement('div');
commentHeader.className = 'comment-header';
commentHeader.textContent = commenterName;

const commentBody = document.createElement('div');
commentBody.className = 'comment-body';
const commentTextDiv = document.createElement('div');
commentTextDiv.className = 'comment-text';
commentTextDiv.textContent = commentText;

commentBody.appendChild(commentTextDiv);

newComment.appendChild(commentHeader);
newComment.appendChild(commentBody);

parentList.appendChild(newComment);
}
</script>
</body>
</html>
7 changes: 6 additions & 1 deletion styles.css
Original file line number Diff line number Diff line change
Expand Up @@ -130,8 +130,13 @@ body {
border: none;
border-radius: 18px;
cursor: pointer;
transition: all 0.15s;
}

.add-form-button:hover {
opacity: 0.9;
opacity: 0.8;
}

.add-form-button:active {
opacity: 1;
}
Loading