Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

JavaScript

limor
seal-mask
.a{fill-rule:evenodd;}techdegree
limor
Full Stack JavaScript Techdegree Student 8,239 Points

Margin issues when using .appendChild in Javascript

I'm working on Unit 2 of Full Stack JavaScript – List Pagination and Filtering.

Using JavaScript, I was able to append page links to my HTML and all the page links function properly. However, it looks like there's an issue because the pagination buttons have no space between them (unlike the example Treehouse provided). I also haven't manipulated the CSS or HTML files. In DevTools, my code looks the same as the Treehouse example.

How can I use .appendChild and have the HTML code formatted properly? What exactly is causing this spacing issue?

This is my JavaScript:

const page = document.querySelector(".page");
const div = document.createElement("DIV");
div.className = 'pagination'; 
const ul = document.createElement("UL");
ul.innerHTML = '';
div.appendChild(ul);
page.appendChild(div);

for (let i = 0; i < students.length / 10; i++) {
    const li = document.createElement("LI");
    const pageLink = document.createElement("A");
    pageLink.href = "#";
    pageLink.textContent = i + 1;
    li.appendChild(pageLink);
    ul.appendChild(li);
};

This is the HTML from the example Treehouse provided:

<div class="pagination">
        <ul>
          <li>
            <a class="active" href="#">1</a>
          </li>
           <li>
            <a href="#">2</a>
          </li>
           <li>
            <a href="#">3</a>
          </li>
           <li>
            <a href="#">4</a>
          </li>
           <li>
            <a href="#">5</a>
          </li>
        </ul>
      </div>

https://w.trhou.se/6ju491a1fa