Advertisement
CaptainManiac999

does not detect an element

Oct 28th, 2021
676
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <div class="interactivearea">
  2.          <form class="simplecontrols">
  3.           <label for="authorname" class="cooldesign">Author Name</label>
  4.           <input type="text" class="cooldesign" id="authorname" name="authorname">
  5.           <input type="button" class="cooldesign" id="addauthor" name="addauthor" value="Add Author">
  6.           <input type="button" class="cooldesign" id="removeauthor" name="removeauthor" value="Remove Author">
  7.           <input type="button" class="cooldesign" id="swapallauthors" name="swapallauthors" value="Swap All Authors">
  8.           <br>
  9.           <label for="bookname" class="cooldesign">Book Name</label>
  10.           <input type="text" class="cooldesign" id="bookname" name="bookname">
  11.           <input type="button" class="cooldesign" id="addbook" name="addbook" value="Add Book">
  12.           <input type="button" class="cooldesign" id="removebook" name="removebook" value="Remove Book">
  13.           <input type="button" class="cooldesign" id="replacebook" name="replacebook" value="Replace Book">
  14.           <input type="button" class="cooldesign" id="swapallbooks" name="swapallbooks" value="Swap All Books">
  15.          </form>
  16.          <script>
  17.              class book
  18.              {
  19.                  constructor(_name = "",_year = 0)
  20.                  {
  21.                   this.name = _name;
  22.                   this.year = _year;
  23.                  }
  24.  
  25.                  getname = function()
  26.                  {
  27.                      return this.name;
  28.                  }
  29.  
  30.                  getyear = function()
  31.                  {
  32.                      return this.year;
  33.                  }
  34.  
  35.                  getallinfo = function()
  36.                  {
  37.                      var allinfo = "Book Info: \n Name: " + this.name + "\n Year: " + this.year + "\n";
  38.                  }
  39.  
  40.                  setname = function(_name)
  41.                  {
  42.                      this.name = _name;
  43.                  }
  44.  
  45.                  setyear = function(_year)
  46.                  {
  47.                      this.year = _year;
  48.                  }
  49.  
  50.              }
  51.              class author
  52.              {
  53.                  constructor(_name = "",_yearofbirth = 0,_books = [])
  54.                  {
  55.                      this.name = _name;
  56.                      this.yearofbirth = _yearofbirth;
  57.                      this.books = _books;
  58.                  }
  59.  
  60.                  getname = function ()
  61.                  {
  62.                      return this.name;
  63.                  }
  64.  
  65.                  getyearofbirth = function()
  66.                  {
  67.                      return this.yearofbirth;
  68.                  }
  69.  
  70.                  getbooks = function()
  71.                  {
  72.                      return this.books;
  73.                  }
  74.  
  75.                  getallinfo = function()
  76.                  {
  77.                      fullinfo = "Author Info: \n Name: " + this.getname() + "\n Birth Year: " + this.getyearofbirth() + "\n Books by this author: " + this.getbooks() + "\n";
  78.                      return fullinfo;
  79.                  }
  80.  
  81.                  setname = function(_name)
  82.                  {
  83.                      this.name = _name;              
  84.                  }
  85.  
  86.                  setyearofbirth = function(_yearofbirth)
  87.                  {
  88.                      this.yearofbirth = _yearofbirth;
  89.                  }
  90.  
  91.                  setbooks = function(_books)
  92.                  {
  93.                      this.books = _books;
  94.                  }
  95.  
  96.                  addbook = function(_book)
  97.                  {
  98.                      books.push(book);
  99.                  }
  100.  
  101.                  removebook = function(_book)
  102.                  {
  103.                      for(book in books)
  104.                      {
  105.                          if(book === _book)
  106.                          {
  107.                              books.splice(books.indexOf(book),1);
  108.                          }
  109.                      }
  110.                  }
  111.  
  112.              }
  113.              var authors = [{name:"Иван Вазов", yearofbirth: 1850,books: [{name: "Под Игото",year : 1893},{name: "Немили-недраги", year: 1883},{name: "Чичовци",year:1885}]}];
  114.              var authornameinput = document.getElementById("authorname");
  115.              var addauthorbutton = document.getElementById("addauthor");
  116.              var removeauthorbutton = document.getElementById("removeauthor");
  117.              var swapallauthorsbutton = document.getElementById("swapallauthors");
  118.              var booknameinput = document.getElementById("bookname");
  119.              var addbookbutton = document.getElementById("addbook");
  120.              var removebookbutton = document.getElementById("removebook");
  121.              var replacebookbutton = document.getElementById("replacebook");
  122.              var swapallbooksbutton = document.getElementById("swapallbooks");
  123.              var interactiveareaelement = document.getElementById("interactivearea");
  124.  
  125.              function CreateElementForArrayItem(arr = [],parentelement)
  126.              {
  127.                  if((parentelement !== undefined && arr !== undefined) && (parentelement !== null && arr !== null))
  128.                  {
  129.                      for(item of arr)
  130.                      {
  131.                          var itemcontainer = document.createElement("div");
  132.                          itemcontainer.classList.add("cooldesign");
  133.                          itemcontainer.classList.add(typeof item);
  134.                          parentelement.appendChild(itemcontainer);
  135.                      }
  136.                  }
  137.              }
  138.              console.log(interactiveareaelement);
  139.              CreateElementForArrayItem(authors,interactiveareaelement);
  140.          </script>
  141.      </div>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement