Is there a way for me to showcase my JSON data in a horizontal layout that resembles that of an online shopping platform

I have been utilizing an API to retrieve specific types of purses from a retailer's website. After formatting the JSON data, I am able to display the purse image and name. However, they are currently displayed vertically, one per row. I aim to present these items next to each other in a layout similar to ecommerce sites. How can I achieve this? Below is the code snippet without including my API key for privacy reasons. Thank you in advance.

$(document).ready(function(){
//initiate HTTP request
        $.get("http://api.vsapi01.com/search/by-url?apikey=[insert key here]0&url=https://product-images4.therealreal.com/BAL31068_2_product.jpg&index=real-bags ", function(data){
               
         data['images'].forEach(function(image,index,images) { 
            var bagName = image.title;
           
            var clickURL = image.pageUrl;
            var pictureURL = image.imageUrl;
  var image = "<img src=\""+pictureURL+"\"/>";
            var clickableImage = "<a href=\"" + clickURL + "\">" + image + "</a>";
            var wholeImage = "<div>"  + clickableImage + "<br>" + bagName + "<br> " + "<div>";                      
            $( ".display" ).append(wholeImage);
            });
       });
     });
<div class="display"></div>

Answer №1

As emphasized by Sarah in her response, it is important to remember that the display attribute of the .display selector should be defined as inline-block:

.display {
    display: inline-block;
}

Elaboration

The reason for this adjustment is due to the fact that the default behavior of a div element is to be displayed as a block item, resulting in it moving to a new line after each block. By setting the display property to inline-block, the element will retain its block characteristics while allowing multiple blocks to appear on the same line.

Want to Learn More?

Explore CSS Display Property on MDN

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

accessing data from JSON using a dynamic key

Here is my JavaScript code: var data = {'color':'red'}; // dynamic json data. for(key in data) { alert(key); } In this code snippet, the alert gives us the json key color. But how can we retrieve its value? Please note that the j ...

Evaluating string combinations in JavaScript using valid comparisons

After choosing values on the screen, two variables store their value. var uval = '100'; var eval = '5'; There are 2 combinations with values: let combination1= 'u:100;e:1,4,5,10' let combination2 = 'u:1000;e:120,400,500, ...

How can I apply innerHTML to each item in a forEach loop?

I need the innerHTML of each <a> tag to change, so that if it says <a>facebook</a>, it should be changed to <a><i class='fab fa-facebook'></i></a>. <main class="non"> <div class=" ...

Transforming JSON data into a Model class

I'm having trouble converting the server response into a model class. Below is the code I am using. void main() { //JSON to parse var strJson = """{ \"person\": [ {\"name\": \"Mahendra\", \"age\": ...

The magnifying glass icon is missing from the autocomplete search feature

After creating an autocomplete search functionality that queries my mysql database, I encountered a slight issue. Here is the code snippet showcasing my implementation: <div class="search-bar"> <div class="ui-widget"> <input id="ski ...

What causes the warning message at runtime from propTypes when auto binding props?

Explanation: I created a basic wrapper to automatically bind the props. Code Snippet: To implement this, start by using create-react-app to set up a new application. Then, replace the contents of App.js with the following code: import React, { Comp ...

Focused on individual characters in a string to implement diverse CSS styles

Is there a way I can apply different CSS classes to specific indexes within a string? For example, consider this string: "Tip. \n Please search using a third character. \n Or use a wildcard." I know how to target the first line with CSS using : ...

What is the alternative to using javascript onclick(this.form) in jQuery?

I have a current setup that looks like this: <form action="cart.php?action=update" method="post" name="cart" id="cart"> <input maxlength="3" value="25" onKeyup="chk_me(this.form)" /> etc.. </form> The onKeyup event triggers the chk_me ...

Error: The package is currently undefined in Grunt

When I run the command: The default task is concatenation. grunt -v I encounter the following Error message: Verifying property concat.dist exists in config...Warning: An error occurred while processing a template (pkg is not defined). Use --force to ...

A guide on adding or removing a node at a specified location within a JSON file using PHP

I am struggling to insert a new node into a deeply nested JSON file. I am having difficulty determining the array index where the node should be added. This pertains to handling and managing collaterals in a JSON file. I attempted to utilize the array_spl ...

Are there any methods to determine the way in which a user has absorbed the content of a post

This particular question sets itself apart from the one found here, as it aims to detect various user behaviors beyond just browser activity. Specifically, I am interested in identifying behaviors such as: Rapidly skimming through an article from start ...

Issue with making Flickr API request using XMLHttpRequest receiving an unsuccessful response

I'm having issues trying to retrieve a JSON list from Flickr using plain JavaScript and XMLHttpRequest. Here is an example of an AJAX call without a callback function that is not functioning properly: var url = "https://api.flickr.com/services/feed ...

The operation of my NodeJS application suddenly halts

In my project, I have a Server.js file that I run from the command line using: node server Within the Server.js file, a new instance of class A is created Class A then creates instances of both class B (web socket) and class C (REST API) If the web socket ...

Executing control with AngularJS when ng-change event occurs

When using AngularJS One interesting scenario I encountered is having a ng-change event on a text field and seeing the function being called correctly: <input type="text" ng-model="toggleState" ng-change="ToggleGroupVisiable()" data-rule"" /> The ...

Encountering a Typescript TypeError in es2022 that is not present in es2021

I'm attempting to switch the target property in the tsconfig.json file from es2015 to es2022, but I am encountering an error while running tests that seem to only use tsc without babel: Chrome Headless 110.0.5481.177 (Mac OS 10.15.7) TypeError: Can ...

The text fields keep duplicating when the checkbox is unchecked

There are check boxes for Firstname, Lastname, and Email. Clicking on a checkbox should display the corresponding input type, and unchecking it should remove the input field. I am also attempting to retrieve the label of the selected checkbox without succ ...

What is the best way to save an AJAX response to a class attribute?

I'm currently in the process of creating a model-like Class which, upon initialization, triggers an AJAX request. My goal is to save the response from this request as a property within the new object, allowing me to leverage the returned data. However ...

Increasing the number of controller methods in Angular

Within AngularJs, I have multiple controllers that share similar functions: angular.module('myApp').controller(...){ function lockForm(id){ ... } function releaseForm(id){ ... } function dbError(e){ ...

Service update causing $scope in Ionic Angular Cordova to remain stagnant

As a newcomer to Angular, I've been working on a project to create an app that can answer questions, select images, and send data to the server. I'm facing some challenges with updating the scope properly when a user selects an image. It seems l ...

determine the proportion of the item

My function is supposed to map an object to create new keys. The new key "percent" is meant to calculate the percentage of each value of the key "data". It should be calculated as the value divided by the sum of all values. However, for some reason, it&apo ...