I am interested in duplicating the li elements retrieved from a JSON source

$.getJSON("leftlist.json" , function(data) {
        $.each(data.articles,function(){
        $('#ullist').before("<li id='mylic' style= color:blue class='item new"+cc+"'> "+el.name+"<div class='block'><div class='row'><button   onclick='copy()' id=btnc class='col button color-blue'>copy</button><button class='col button color-blue'>fav</button><button class='col button '><a class='a2a_dd' href='https://www.addtoany.com/share'><img src='imgs/share.png' width='171' height='16' border='0' alt='Share'/></a></button></div></li></div>");

        })
   });

Answer №1

According to Sathish Thangaraj, the .append() method should be used:


// Accessing JSON data from an API

$.getJSON("https://www.json-generator.com/api/json/get/cpPsULBvKG?indent=2", function(data) {
  $.each(data, (i, el) => {
    $('#json_data').append(`<li>Value: ${el.value} | Key: ${el.key}</li>`);
  });
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<ul id="json_data">

</ul>

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

I am receiving an undefined value when using document.getElementsByClassName

<canvas id="can" height="500px" width="1200px"></canvas> <div class="name"> <h1>LEONARDO</h1> </div> <script> var name=['WATSON','LEONARDO',"SMITH","EMILY"] var counter=0 var dat ...

JavaScript doesn't pause for the data to come back, resulting in an undefined value

When I call the function "classTableData" on a button click, my allData variable becomes undefined. The problem seems to be that it processes the next line of code without waiting for the results, causing allData to remain empty. Can anyone provide some ...

How can I incorporate popups in React using mapbox-gl?

Currently utilizing mapbox-gl within React, everything seems to be functioning properly except for the integration of mapbox-gl's Popups. I have the function let Popup, but I am uncertain about how to incorporate it. renderMap() { if (this.props. ...

Why does the CSHTML button containing a JavaScript onclick function only function intermittently?

I've implemented a download button on a webpage that dynamically assigns an ID based on the number of questions posted. Below is the code for the button: <input data-bind="attr: { id: $index() }" type="button" value="Downlo ...

Alert: Unauthorized hook call and Exception: Cannot access properties of null (reading 'useState')

I am currently working on a project using ASP.NET Core with React. To bundle my code, I have opted to use Webpack 5. Within the index.jsx file, I have the following code: import { useState } from "react"; function App() { const [value, setV ...

Issues with simple jquery and javascript: unable to add the class ".has-error" and onclick event not properly defined

Currently, I am working with jQuery version 2.1.4 and JavaScript to implement a straightforward form validation using Bootstrap. During this process, I have encountered three peculiar issues. While I am confident that my jQuery code is properly functi ...

Retrieve the key name that contains a specific value in JSON data

Currently, I am utilizing the JSONAta library to navigate a complex object. My goal is to extract the keys that meet specific conditions. { "properties": { "WTID": { "pattern": "referen ...

"Cookie Magic: Unleashing the Power of Ajax and

I am currently working on an ASP.NET 3.5sp1 application with a single page layout where all interactions are handled through ajax, eliminating the need for postbacks. The website in question is . This app does not require user accounts and allows anonymou ...

Execution of Ajax call fails to occur synchronously

I have created a unique weather website that utilizes the flickr API as well as the yahoo API to gather weather data. However, I am facing an issue where the ajax call from the yahoo API does not retrieve the necessary data in time for the content of the p ...

What causes the element to remain visible despite the changes made to the v-show attribute?

<!DOCTYPE html> <html> <head> <title>test</title> <script src="https://unpkg.com/vue"></script> </head> <body> <div id="app"> <p v-show="show&qu ...

Exclude mock files from webpack configuration in AngularClass/angular2-webpack-starter for production builds

I've encountered some obstacles while working with the AngularClass/angular2-webpack-starter framework, specifically in configuring its webpack settings. My goal is straightforward, yet I've been struggling to achieve it. In my project directory ...

What's the best way to align divs vertically in a compact layout?

Update The reason I require this specific behavior is to ensure that all my content remains in chronological order, both on the web page and in the HTML structure. This way, even if the layout collapses into a single column on smaller screens, the content ...

Tips for adding text to your d3 force layout

Looking to incorporate text into a force layout using SVG. I've created an svg group and added a circle successfully, but having trouble with the text. Here's the code snippet: var node = svg.selectAll("g") .data(measures.nod ...

The integration of Material-UI Autocomplete and TextField causes google autocomplete to activate

I am currently working on integrating the Autocomplete component into my project. However, I am facing an issue where the browser's autofill/autocomplete feature kicks in after some time. Is there a way to disable this behavior? ...

Vanilla JavaScript: toggling text visibility with pure JS

Recently, I started learning javascript and I am attempting to use vanilla javascript to show and hide text on click. However, I can't seem to figure out what is going wrong. Here is the code snippet I have: Below is the HTML code snippet: <p cla ...

Tips for retrieving an element's outerHTML, innerHTML, and text content using JavaScript

I am new to the protractor framework and I have been struggling to find a way to access, using outerHTML/InnerHTML/getText(), the child elements in order to test if an <img> element is being displayed on a view. Specifically, I am working with an ng- ...

Having trouble retrieving information from a JSON object? Unable to retrieve property 'company_about' of an undefined object?

Here is the JSON data I have: [ { "id": 1, "job_id": 1, "company_profile": "Sales and Marketing", "company_about": "Established in 1992 , it is a renouned marketing company", "company_product": "Ford,Mustang,Beetle", "key_skills": ...

Using MEAN.JS to Define Query Parameters for Mongo from the Client Controller

I am currently developing an application using the MEAN stack - MongoDB, Angular, Express, and Node.js. To kickstart my project, I utilized the MEAN.JS generator to set up the initial structure of my application. The articles module within my application ...

Tips for removing the "" character from a JSON string using JavaScript

At my node js server, I am receiving a json string that has the following format: {\"gID\":1,\"sID\":18,\"T\":\"Parking\"} I added the "\" in the string because it was created in C and the \ is used to es ...