From the course: Ajax with PHP: Add Dynamic Content to Websites

Unlock the full course today

Join today to access over 22,600 courses taught by industry experts or purchase this course individually.

Append HTML results

Append HTML results

From the course: Ajax with PHP: Add Dynamic Content to Websites

Start my 1-month free trial

Append HTML results

- [Instructor] Now that we understand the starting code, we're ready to roll up our sleeves and implement infinite scrolling. The next step is to append those HTML results to an element in the DOM, or document object model. So how do we take this block of HTML that's here, and put it inside the div that's up here? In the past we've been using innerHTML to set the value of that HTML, and it's possible to use innerHTML here, but it's not the best choice, and the reason why is the innerHTML is used to replace the entire contents of a div. We don't want to replace the contents, we want to append them to the end. So we're going to have to do it a little bit differently. Let's go into our code, and inside the LoadMore function, right here where we append results to the blog post, so right below append results to end of blog post, let's write a call to a new function, which doesn't exist yet. We'll call it appendToDiv, and it's going to have two arguments. We're going to pass it the…

Contents