The CSS I've written isn't functioning properly within a div that was generated using

I have been trying to populate a div with data using JSON, but I am facing an issue where my div, which is set with JavaScript for each JSON element, does not seem to be working correctly. The classes "lulu" and "lora" are not being recognized. Apologies for my poor English, I hope my explanation was clear.

Could someone please assist me with this problem? Thank you.

Below is the code I am using:

Javascript:

<script type="text/javascript">
  $(function() {
    var url = "animals.json";

    $.getJSON(url, function(json) {
      $.each(json.cats, function(i, item) {
        $('<div class="lulu">' + 
          '<img src="pics/style/blank.gif" data-src="img/' + item.pictures + '.jpg"/>' +
          '<img class="lora" src="img/' + item.picsmall + '.jpg"/>'+'</div>')
          .appendTo('#Mittelt');
      });
    });
  });
</script> 

HTML:

<div class="rosa" id="Mittelt">
  // Placeholder for content
</div>

JSON:

{"cats":[
         {"id":"1",
          "pictures":"mia",
          "picsmall":"miasmall"}
         ]
}

CSS:

.lulu {
    position: absolute;
    height: 100%;
    -webkit-transform: translateZ(0px);
    -ms-transform: translateZ(0px);
    -o-transform: translateZ(0px);
    transform: translateZ(0px);
}

The JSON data is being retrieved successfully, but it seems like the classes are not being applied as intended.

Thank you for any help in advance.

Answer №1

It seems there is a slight error in the JSON format of animals.json.

Here is what needs to be included:

var jsonData = url["dogs"];  
 $(jsonData).each(function(i, dog){  
    console.log(dog.id);  
   i=dog[0];

Check it out on CodePen here: http://codepen.io/nagasai/pen/gMwXaK

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

Tips on positioning two images in separate locations within a table cell?

I have a cell containing two images. I want one to be centered in the middle of the cell and the other in the top right corner, overlaying the centered image. My goal is to achieve this layout https://jsfiddle.net/5bL56a34/ without specifying the left m ...

Dealing with JQuery and CSS issues on Internet Explorer

Recently, I've been working on a code snippet to maximize a video panel upon page load or resize. Utilizing JQuery 1.4.4, the implementation has been smooth sailing on Chrome, Firefox, and Safari. Drawing inspiration from various online resources, I&a ...

Switch out the HTML content within the JavaScript include

Here is the situation: <script type="text/javascript" src="http://xy.com/something.js"></script> This code snippet in my PHP/HTML file loads the entire something.js file. Inside that file, there are lines containing "document.write..." which ...

What could be causing the icon link to not show up in Bootstrap 4?

Currently, I am engrossed in reading the book titled "ASP .NET MVC 5." However, I have hit a roadblock. The author utilizes Bootstrap 3 in the book, but the newer version of Bootstrap contains some modifications that are causing me difficulties in solving ...

Parsley JS failing to validate

I attempted to validate my form using parsley.js, following the instructions from the official documentation. However, for unknown reasons, it is not functioning as expected. Below is the code snippet: <div class="container"> <div class= ...

I'm facing an issue where Typescript isn't recognizing Jest types

The Challenge Setting up a TypeScript project with Jest has been proving difficult for me. It seems that TypeScript is not recognizing the Jest types from @types/jest, resulting in an error message like this: Cannot find name 'test'. Do you nee ...

What is the best way to send a string value from HTML to a JavaScript function as a parameter?

When embedding HTML codes in Java, I encountered an issue where I needed to pass a string value from HTML to a JavaScript function. Initially, I tried using the following code: out.print("<script>init("+macId+")</script>"); However, this meth ...

Challenges arise when adjusting frame size for mobile and desktop devices

I am trying to achieve an auto-resize feature for my frame's height when the screen width is smaller than a certain value. I want it to behave like Sketchfab, as demonstrated in this video: http://www.youtube.com/watch?v=_y5ckVFGHKU&feature=youtu. ...

What is the best way to prepopulate an HTML form field for email submission?

Looking for a way to prepopulate the subject field in an HTML form with To and From fields? I'd like to achieve this using JS or jQuery. I want the message to say "Hi, thanks for stopping by (followed by the rest of the message)..." just like LinkedI ...

JavaScript Firebase: Service worker malfunctioning during navigation

I'm currently developing a website that relies on firebase messaging. To make this happen, a specialized service worker for firebase has been integrated into the site. This website functions as a webchat platform where messages are synchronized and s ...

How come this variable isn't recognized as 0 even though the debugger is indicating otherwise?

I am currently working on a React component that receives the total number of reviews as a prop. In cases where the number of reviews is 0, I intend to display an element indicating <div>No reviews yet.</div> If there are reviews available, I ...

JavaScript nested function "invalid function"

Recently, I've encountered an issue with a JavaScript file that I'm including on my page. Here's a summary of the situation: var PageTransitions = (function() { function setCurrent(currentSet) { alert(currentSet); } fu ...

Should you hold off on moving forward until the asynchronous task finishes?

My goal is to retrieve location coordinates using the Google Maps JavaScript API in an asynchronous manner. Below is the function I've created for this purpose: function fetchCoordinates(address) { var geocoder = new google.maps.Geocoder(); ...

What is the process for spinning a span in the center of an image?

My canvas displays an image: https://i.sstatic.net/p3MV4.png There is a white square with a refresh icon on the right side of the image, slightly hidden by a black circle. I implemented it like this: var rotatorSpan = document.createElement("span"); rot ...

Preserving Selected Option in a Dropdown After AJAX Call in a Partial View

Within my ASP.NET Core web application, I am faced with a scenario where a partial view needs to be integrated into multiple views. This partial view must be able to adapt to dynamic data based on the specific view that triggers its rendering. The area hig ...

AngularJS is patiently awaiting the completion of the translation rendering process

I implemented the ngCloak directive to my body element on the page and every angular-related element, but it appears that it is not working with AngularJS translate. The translate variables show up on the page initially and then get translated after a se ...

Trouble with Colorbox loading? Here's a quick fix!

I'm experiencing a frustrating issue. Although I have successfully used colorbox in the past, it is not working on a new website I am developing. All necessary files, including jquery and colorbox, are located in the same directory as the html file. ...

Retrieve the offspring with the greatest level of depth within a parental relationship

Consider the following tree structure: -root | | |-child1 | |-innerChild1 | |-innerChild2 | |-child2 I am looking to create a JavaScript function that can determine the depth of an element within the tree. For example: var depth = getInnerDepth( ...

Remove default value from jQuery dropdown list

Having difficulty selecting an existing blank value in a dropdown using jQuery. Despite the presence of the blank option, setting it with $('#studyList option[value=""]').prop('selected', 'selected'); is not working. Is there ...

What is the best way to retrieve JSON format using ODATA?

I am aware that ODATA has the capability to return JSON, however I am unsure if I need to use a specific attribute or interface in order to achieve this. My goal is to have my odata service function similarly to ?$format=JSON, but unfortunately my service ...