<div> placed within a <ul>

I have implemented a fetch function to retrieve data from a SharePoint form that is currently stored in a SharePoint list, and then display it on an HTML page.

In my code snippet available at this link, the expected output matches the actual output perfectly. The fetched data is appended to a <ul> element inside a <li> element (as the data is received as a string rather than being properly retrieved through fetch).

However, the issue I'm encountering with the fetch operation is that instead of directly adding the data to the <ul> element, it gets added within a <div> element inside the <ul>. This might be due to the fact that <div> elements are not allowed within a <ul>.

1.) Why does the data get inserted as

<ul><div> </div></ul>
? Is this related to the column type in the form being "Multiple lines of text entry"?

2.) What would be the best approach to rectify this situation?

This is how the content is being displayed based on the inspect element:

<h4> Training </h4>
<ul>- 
  <div>Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur.</div>
</ul>

Lastly, here's a snippet of my JS/HTML code:

[JS/HTML code snippet]

Answer №1

One simple solution to this problem is to remove any HTML that SharePoint may be including in the data. Modify your <ul> lines from something like:

  listContent += '<ul>' + "- " + data[i].Travel + '</ul>';

to:

  listContent += '<ul>' + "- " + data[i].Travel.replace(/(<([^>]+)>)/gi, "") + '</ul>';

This syntax for replacing tags was inspired by an article on removing HTML tags: https://css-tricks.com/snippets/javascript/strip-html-tags-in-javascript/

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

Retrieving user input from an angular controller function

I have a $resource object in Angular that looks like this: { _id: '1' items: [ {_id: 'a'}, {_id: 'b'}, {_id: 'c'} ] } My goal is to create a form with a checkbox for each element in the items array. In th ...

Is there a way to create a rectangle shape and connect it with data from a Json file on a page

Is it possible to draw rectangles on a page.aspx? For example, by using data from a JSON object like {name:Food;name:Candy;name:Water;name:Meat;......}, where each rectangle corresponds to the count of different data names. If there are 4 names in the data ...

The expected response from CSS3 animated images may not be fully realized

I've been working on this project with 4 images. While hovering over one image causes the others to change size as intended, I can't figure out why the ones on the left are not following the same pattern even though I have specified that they sho ...

Developing a persistent header/footer template in jQuery Mobile and PhoneGap

I'm embarking on the journey of developing a mobile app using jQuery Mobile/PhoneGap. I've decided to use this template as my starting point, which utilizes HTML/JS for page creation. Instead of cramming all the <page> tags into a single ht ...

What is the best way to send JavaScript data to PHP?

Is it possible to post a variable to a PHP script without refreshing the page? If so, how can this be achieved? Here is an example using jQuery: $.ajax({ url: "myphpfile.php", type: "post", data: json/array/whatever, success: function(){ ...

Passing data from a textbox on a PHP page to a textbox on an ASP.NET website

I'm working on a PHP website that includes a login form. When students enter their username and password, I want them to be redirected to an ASP.NET website (not mine) that also requires a login. I want the username and password they entered on my PHP ...

Rotating Cursor during AJAX loading process

I utilize a WebGrid across many of my pages to showcase various products. Within the code snippet below, you can see how an item is added to the database when a user clicks on it: public bool ToCart(int userId, string partNumber, ...

How to submit form data with a POST request in Flask using fetch without having to reload

Despite reading numerous similar questions, I am still unable to determine how to achieve my goal. I have multiple forms on a single page and I am trying to submit data from each form without refreshing the page. Below is an example of one of the five form ...

Tips for implementing multiple CSS image filters with jQuery

Can you show me how to use jQuery to apply the CSS code below? #centeredImage { -webkit-filter: grayscale(20%) invert(0) blur(1px); } I attempted this method already, but it didn't have any effect. $('#centeredImage').css('-webki ...

What is the best way to extract a specific field's list from a nested list of objects?

I am working with MongoDB documents that contain a pokemon array, where each item is an object. Here's a sample document: { _id: ObjectId("60a8f82df06d8601849b2a01") pokemon: [ { "id": 1, "num": 1, ...

Increase the identification of HTML element with jQuery

I've encountered an issue while trying to increment the id of 2 HTML elements, hwAddition and itemNumber, upon a button click event. The HTML code in question is as follows: <div id="hwAddition"> <div id="itemNumber" s ...

"Using jQuery to ensure multiple sections are ready for manipulation on

After some experimentation, I made an interesting discovery: I can actually include $(document).ready(function(){}); multiple times. For example: $(document).ready(function(){ var abc = "1122"; //do something.. }); $(document).ready(function() ...

Customizing the starting number of rows per page in TablePagination from material-ui

As a newcomer to using materials, I am looking to customize the table pagination to show 'n' number of rows, for example 10, and remove the "Rows per page" dropdown. <TablePagination rowsPerPageOptions={[]} component="div" ...

Receiving an ajax request to refresh the table

I'm facing an issue with an ajax call that is supposed to update a table (max) on the current page, but it doesn't seem to be working correctly. I suspect that the problem lies in the function on the initial page because the next page is not rece ...

Selecting elements with jQuery allows you to manipulate the

Encountering issues with jQuery selectors. This is how my HTML looks: <form method="" action=""> <p id="question_1"> <h1 id="question">1. A Question</h1> <div id="choices"> ...

Creating a countdown timer for a specific date and time using web technologies

I'm looking to create a timer countdown that is set to a specific date and time, such as June 1st at midnight. The code should display the remaining time until that date or time. ...

The Npm generate script is failing to create the necessary routes

I've integrated vue-router into my nuxt project, but I encountered an issue when running npm run generate - it generates everything except for my pages. I suspect the problem lies with the router implementation as I didn't face any issues before ...

Error injecting Angular components

Here is the structure of my HTML file: <html> <head> <title>PLD Interaction pattern</title> <link href="css/bootstrap.min.css" rel="stylesheet" type="text/css"/> </head> <body ng-app="myT ...

CSS to align text to the right side

I'm having a CSS issue that I've been struggling with. Despite spending ample time trying to complete the task, I find it too challenging. Now, I turn to all of you (webmasters/developers) for help in solving this problem. Could you please take ...

I'm having issues with the functionality of my code inside the ng-template and ngIf. What could be

I am facing an issue with my method that is supposed to display the specified HTML content. However, it seems like the ngIf condition within the code block is not functioning correctly. Can someone help me understand why the ngIf statement is being ignored ...