Pellentesque nec neque ex. Aliquam at quam vitae lacus convallis pulvinar. Mauris vitae ullamcorper lacus. Cras nisi dui, faucibus non dolor quis, volutpat euismod massa. Donec et pulvinar erat.
Hi Jake, there is something wrong with the formatting of your message. Did you forget a closing character?
You need to iterate the results like I showed already and create an <a> element for each result with its href attribute set to the value of item.link.
result.items.forEach(item=>{/* create an <a> element */vara=document.createElement('a')/* set the href attribute to the value of item.link */a.setAttribute('href',item.link)/* also set a clickable text of course */a.innerText=item.title/* select the element you want to insert the link into
i assume here that is a div with id="results" */varresultsDiv=document.getElementById('results')/* insert the <a> into the result div */resultsDiv.appendChild(a)})
Voila! And you are done.
You will notice that every link will appear on one line this way, so you want to wrap them in a <p> element or some other element that automatically does a newline. You have two options here.
Option 1 is to create an additional <p> element and inject the <a> into that, the second option is just writing the HTML you want in a single line. A little ugly but works too and nothing wrong with it. For example:
result.items.forEach(item=>{/* basically this says, replace the innerHTML of this div
with what is already there + our new extra HTML */varresults=document.getElementById('results')results.innerHTML=results.innerHTML+`<p><a href="${item.link}">${item.title}</a></p>`})
Ah yes I see that mistake. Thank you so much for your quick reply, this helps massively! This is exactly what I need. I tried using 'results.innerHTML' but I had passed the string incorrectly it seems. I have this working perfect now, and all of your helpful information has made it easy to understand why it works. Once again thank you so much!
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
Hi Jake, there is something wrong with the formatting of your message. Did you forget a closing character?
You need to iterate the results like I showed already and create an <a> element for each result with its href attribute set to the value of item.link.
Voila! And you are done.
You will notice that every link will appear on one line this way, so you want to wrap them in a <p> element or some other element that automatically does a newline. You have two options here.
Option 1 is to create an additional <p> element and inject the <a> into that, the second option is just writing the HTML you want in a single line. A little ugly but works too and nothing wrong with it. For example:
If you are using jQuery it is even easier.
If you made it through the tutorial then this should really answer your question.
Ah yes I see that mistake. Thank you so much for your quick reply, this helps massively! This is exactly what I need. I tried using 'results.innerHTML' but I had passed the string incorrectly it seems. I have this working perfect now, and all of your helpful information has made it easy to understand why it works. Once again thank you so much!