我需要快速帮助来设置 createElement,如下所示:
<h1 class="headingTitle"> ENDANGERED <span class="subHeading">Animals</span> </h1>
我做了这个,但它产生了一个错误,这是:
未捕获的错误:NotFoundError:DOM 异常 8
//Adds 'containr' div to the body
var containerElement = document.createElement('div');
containerElement.setAttribute('class','container');
document.body.appendChild(containerElement);
//Add the ENDANGERED ANIMALS title
var title = document.createElement("h1");
title.setAttribute('class', 'headingTitle');
var text = document.createTextNode("ENDANGERED");
var span = document.createElement('span');
span.setAttribute('class', 'subHeading');
var subText = document.createTextNode("Animals");
span.appendChild(title);
title.appendChild(text);
document.getElementsByClassName('container')[0].appendChild(title);