Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

append javascript example

const formDataId = document.getElementById("userForm");
const formData = new FormData(formDataId);
formData.append("isAdmin", 1);
Comment

js append sample

const container = document.querySelector(".container");
const songsContainer = container.querySelector(".songs-container");
const addButton = container.querySelector(".input__btn_action_add");
const resetButton = container.querySelector(".input__btn_action_reset");
const noSongsElement = container.querySelector(".no-songs");

function renderHasSongs() {
  resetButton.removeAttribute("disabled");
  resetButton.classList.remove("input__btn_disabled");
  noSongsElement.classList.add("no-songs_hidden");
}

function renderNoSongs() {
  resetButton.setAttribute("disabled", true);
  resetButton.classList.add("input__btn_disabled");
  noSongsElement.classList.remove("no-songs_hidden");
}

function addSong(artistValue, titleValue) {
  const songTemplate = document.querySelector("#song-template").content;
  const songElement = songTemplate.querySelector('.song').cloneNode(true);

  songElement.querySelector(".song__artist").textContent = artistValue;
   songElement.querySelector(".song__title").textContent = titleValue;
  
  songsContainer.append(songElement); 
}

addButton.addEventListener("click", function () {
  const artist = document.querySelector(".input__text_type_artist");
  const title = document.querySelector(".input__text_type_title");

  addSong(artist.value, title.value);
  renderHasSongs();

  artist.value = "";
  title.value = "";
});

resetButton.addEventListener("click", function () {
  const songs = document.querySelectorAll(".song")

  songs.forEach((item) => {
    item.remove();
  });

  renderNoSongs();
});
Comment

PREVIOUS NEXT
Code Example
Javascript :: Serve JSON on a Specific Route 
Javascript :: angualr js checknbox not working js 
Javascript :: change string to object in html 
Javascript :: uniqSort 
Javascript :: checkout code 
Javascript :: constantly send a request until a desired response is recieved expressjs 
Javascript :: Make a ReactNative component take the height and width of the current window 
Javascript :: how to show conditional show on select field 
Javascript :: how to add ajax loading icon in jquery 
Javascript :: js import 
Javascript :: karma get attribute 
Javascript :: register js in viewyii2 
Javascript :: Conditionally add members to an object 
Javascript :: install reactivesearch 
Javascript :: typeof regex 
Javascript :: express plus es6 
Javascript :: paramters and arguments 
Javascript :: Lisk Schema example 
Javascript :: Nodemailer Reuseable Code 
Javascript :: "send data with window.location.href and get" 
Javascript :: minutes to seconds javascript 
Javascript :: form needs 2 clicks to submit react 
Javascript :: unable to append div multiple times 
Javascript :: Difference b/w AddEventListener and Attach Event 
Javascript :: utterances reactjs 
Javascript :: next-pwa push notification 
Javascript :: variable hoisting 
Javascript :: Error: listen EACCES: permission denied 5000; 
Javascript :: Method definition shorthand in ES6 
Javascript :: this ....object of. 
ADD CONTENT
Topic
Content
Source link
Name
5+7 =