jQuery append not working for me

jQuery append not working for me
0.0 0


Hello everyone. I’ve been working on a wikipedia viewer project for some time now. I’ve been able to get most of it working but I ran into a snag. I’m trying to create a javascript function that will append my particular css using jquery.
Here’s a link to the project on codepen: Wikipedia project

I’m not getting errors but the issue is either occurring in the way I wrote the function called ‘insertArticles’ or occurring in the way that I’m calling the function in the success key:value pair of the wikipedia ajax request.

This is my first post asking for help and I’m not sure if I provided all the necessary information needed to help me. If there’s anymore info needed just let me know. Thanks for any help in advance. Also, this is for the freecodecamp project called “Build a Wikipedia Viewer”.


OK, a few problems here.

First of all, when you call the function insertArticles, you aren’t calling it. On line 27 you use:


But you need:


The other problem is that the variable data has not scope inside insertArticles - in other words, insertArticle has not idea what it is. An easy solution is to pass it to the function, so line 27 becomes:


and line 2 becomes:

function insertArticles(data) {

Now, that should work.

I would also suggest that instead of appending to the body, you create a div, like with an id of “results” or something, because you are going to have to clear that out for subsequent search results, probably on the first line of insertArticles.


Excellent response. I’ll try the changes now and update shortly. Thanks!

That worked perfectly, thanks so much. And I didn’t even think about having to clear the div for subsequent searches. You rock. :+1:t3: