Всем привет! Не могу доделать до конца задачку с формой: при отправке заполненной формы должна появляться карточка.
function addCard (name, link) {
const placesList = document.querySelector('.places-list');
const placeCard = document.createElement('div');
const placeImg = document.createElement('div');
const placeImgLink = 'background-image: url(' + link + ')';
const placeBtnDel = document.createElement('button');
const placeDescription = document.createElement('div');
const placeName = document.createElement('h3');
const placeBtnLike = document.createElement('button');
placeCard.classList.add('place-card');
placeImg.classList.add('place-card__image');
placeBtnDel.classList.add('place-card__delete-icon');
placeDescription.classList.add('place-card__description');
placeName.classList.add('place-card__name');
placeBtnLike.classList.add('place-card__like-icon');
placesList.appendChild(placeCard);
placeCard.appendChild(placeImg);
placeImg.appendChild(placeBtnDel);
placeCard.appendChild(placeDescription);
placeDescription.appendChild(placeName);
placeDescription.appendChild(placeBtnLike);
placeImg.setAttribute('style', placeImgLink);
placeName.textContent = name;
placeBtnDel.addEventListener('click', function(event) {
placesList.removeChild(placeCard);
});
placeBtnLike.addEventListener('click', function(event) {
placeBtnLike.classList.toggle('place-card__like-icon_liked')
});
};
for (let i = 0; i < 10; i++) {
const name = initialCards[i]['name'];
const link = initialCards[i]['link'];
addCard(name, link);
};
const form = document.querySelector('.popup');
const openForm = document.querySelector('.user-info__button');
const closeForm = document.querySelectorAll('.popup__close');
const addBtn = document.querySelector('.popup__button')
function openCloseForm(event) {
if (event.target.matches('.user-info__button')) {
form.classList.add("popup_is-opened");
}
else if (event.target.matches('.popup .popup__close')) {
form.classList.remove("popup_is-opened");
}
};
openForm.addEventListener("click", openCloseForm);
closeForm.forEach(btn => btn.addEventListener("click", openCloseForm));