The formatting of the list is not being correctly displayed in the Ajax Jquery list

Trying to dynamically generate an unordered list from XML onto a jQuery mobile page has been a bit of a challenge for me. While I can display the items on the page, the styling never seems to work properly, only showing up as plain text with blue links. Is there a different approach I should take to style the list?

<ul id="events-holder" data-role="listview" data-inset="true" data-theme="c"> 
$(document).ready(function(){
    $.ajax({
        type: "GET",
        url: "event_list.php",
        dataType: "xml",
        success: function(xml) {
            $(xml).find('event').each(function() {
                var title = $(this).find('title').text();
                var date = $(this).find('date').text();
                var url = $(this).find('url').text();

                $('<li></li>')
                    .html('<li><a href="'+url+ '" rel="external" data-transition="slide">'+ title +'</a></li>')
                    .appendTo('#events-holder')
                    .trigger('create'); 
            });
        }
    });
});

Answer №1

The issue might be related to your css settings. It seems like there could be a problem with the way you are generating <li> elements dynamically. You may be inadvertently duplicating the <li> tags by creating one using $('<li></li>') and then adding an additional <li> within it when using the .html() function.

Consider removing the <li> tag from the string passed into the .html() method.

Answer №2

Make sure to dial:

document.querySelector("#events-list").classList.add('active');

Once you do that, you're good to go.

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

The page background appears to be incomplete in its coloring

As I work on creating a web application for personal use, my goal is to ensure it is mobile-friendly. However, I've encountered an issue where the background of my language page isn't displaying in full blue color as intended. Despite trying diff ...

Reorganize div elements responsively using Bootstrap 5.0

Struggling with web design using HTML, CSS, and Bootstrap v5.0, I am facing an issue. I have three divs A, B, and C that I want to reorder responsively as shown in the image below. A consists of a h2 and p tag, B includes two buttons, and C displays an ima ...

Utilizing CodeIgniter: Integrating Retrieved Data into PHP Code Using Ajax Requests

On my website built with Codeigniter, there is a side panel. When I click or select any options in the side panel, the relevant content appears on the main panel. The home page URL is http://localhost/main/userinfo When I click on female, the URL is http ...

A dynamic jQuery approach for uploading multiple files on the fly

I am working on a project that involves uploading images through a form. I am unsure of the exact number of pictures that will need to be uploaded at one time. Is there a solution using jQuery/AJAX to add file upload fields dynamically to the form? ...

Encountered an error: "Type error undefined" while attempting to populate a form using AJAX and JSON

Upon inspecting the development console, it's clear that my AJAX request was successful and I've received the necessary JSON data. However, I'm struggling to display it correctly as I keep encountering the error below: Uncaught TypeError: C ...

Using jQuery to toggle the selection of multiple checkboxes

Let's start fresh, no need to worry! This is simply a jQuery question ;) I am currently working on a PHP code where the user sends a query to our database. The form then displays sets of results grouped in tables, each with checkboxes to select the d ...

Implementing Canvas Offset in a jQuery Mobile Environment

I have positioned a pen ready for use at this location. http://codepen.io/prantikv/pen/LEbRKY Currently, I am utilizing a canvas to track mouse movements or touch input. It performs as expected when jQuery or jQuery mobile is not included. However, upon ...

CSS menu LI with horizontal spacing

I'm currently working on aligning the boxes for each <li> tag next to each other without any spaces in between. However, at the moment, there is a significant gap separating each box. How can I eliminate this space? Here is the HTML code snippe ...

Performing an asynchronous HTTP request using AJAX and jQuery's post or get methods

Currently embarking on the creation of a PHP, MySQL, AJAX, and JQuery-powered calendar. While my expertise in the latter two technologies is lacking, I am eager to expand my knowledge. I stumbled upon a script that fulfills my basic requirements, but I hav ...

How to Handle Jquery POST Data in Express Servers

Update Make sure to check out the approved solution provided below. I ended up fixing the issue by removing the line contentType: 'appliction/json', from my POST request. I'm facing a problem trying to send a string to Node.js/Express becau ...

The absence of responseJSON in the jquery ajax response is causing an issue

Currently, I am developing a small web framework for conducting an HCI study and have encountered the following issue: In my setup, I have a Node server running with Express to serve local host data from JSON files. While it may not be the most advanced d ...

Use CSS3 to hide the <li> elements initially and make them appear when the <li> is clicked on

Click here How can I hide the "subline" line from the list and make it visible when the user clicks on the "sub" line, pushing the other lines down? I'm hoping for a solution that doesn't involve using Js or JQuery. Thank you in advance! ...

Resolve Bootstrap columns with varying heights

My Bootstrap row contains a variable number of columns determined by a CMS, sometimes exceeding the space available on one line. I am looking for a way to neatly display all the columns with equal heights. <div class='row'> <div cl ...

Having trouble with your jQuery learning and not seeing any results?

I have been attempting to utilize jQuery for a project, but unfortunately, nothing seems to be happening when I click the button. Despite my various attempts to modify the code, the desired effect still eludes me. I am specifically using Firefox as my bro ...

Unable to access API controller action through AJAX POST call

We are transitioning our server-side logic to be accessed through APIs. I am encountering an issue where the action is not being triggered by my AJAX call. Can someone please review my code and help me identify why I am receiving an error stating that the ...

Ensure this div adapts to different screen sizes

I have attempted using a width of 100%, but unfortunately, it did not result in a responsive design. To illustrate my point, here is the link to what I am striving to achieve in terms of responsiveness: codepen link div { background:url(https://i.stac ...

Clicking on the element will not cause the body to scroll

For some reason, I need to keep the onclick function, but I'm struggling to make it work as intended. What I want is for the body to slide to the next logo when the previous logo is clicked. This is a simplified version of what I have: <div class ...

The RadGrid containing LinkButtons triggers the updating of two distinct controls through RadAjaxManager

I have a radGrid containing two LinkButtons within the ItemTemplate of a column. Outside the grid, I have two separate panels that need to be updated depending on which LinkButton is clicked. For example, if LinkButton1 is clicked, only Panel1 should be ...

The jQuery ajax request functions properly on Internet Explorer but does issues arise when used on Firefox, Chrome, or Opera browsers

I have created a test web page to call a WebApi URL and receive a response. The functionality works perfectly in Internet Explorer, but fails in all other browsers. Below is the jQuery code snippet I am using: $(document).ready(function() { jQuery("# ...

Ensure that Roboto font is utilized on IE 11 and Edge browsers

My goal is to implement the Google Roboto font in my project, but I'm noticing that it doesn't display properly in IE11 / Edge browsers. Below is a snippet of my code: <!DOCTYPE html> <html> <head lang="en"> <meta charse ...