logo
down
shadow

How to add mutiple span to <li> javascript


How to add mutiple span to <li> javascript

By : user3042519
Date : November 28 2020, 12:01 PM
To fix the issue you can do You are requesting a way to achieve your "above" HTML (as you mentioned) but your generated code is vastly different than that. There are "data-ids" , different class-names , etc. Nevertheless , taking for granted that your "above" code is your goal the following 2 ways will produce exactly that. The first way follows your path. Using Native Javascript createElement functions and appending them on DOM elements. The Second way creates a String that represents HTML Code and it inserts it into the DOM creating the whole List.
In both examples i use the Array.prototype.forEach() for the Array loops and the Object.keys() for the Object loops. I also use Arrow functions in those loops which is not necessary though in this case.
code :
let json = "[ { \"Id\":1068, \"Name\":\"Doe\" }, { \"Id\":1070, \"Name\":\"Smith\" },{ \"Id\":1074, \"Name\":\"Jones\" } ]";
let obj = JSON.parse(json);
let list = document.getElementById('servicesList');

obj.forEach((ObjectRow)=>{
 let li = document.createElement("li");
     li.className = "sortable-service-item";

 let Span = document.createElement("span");
     Span.className = "drag-handle-container";
     Span.innerHTML = "<i class='fa fa-bars'></i>";
     Span.setAttribute("data-id", ObjectRow["Id"]);

 li.appendChild(Span);

 Object.keys(ObjectRow).forEach((key)=>{
   let tempSpan = document.createElement("span");
       tempSpan.innerHTML = ObjectRow[key];
       li.appendChild(tempSpan);
 });

 list.appendChild(li);
});     
let json = "[ { \"Id\":1068, \"Name\":\"Doe\" }, { \"Id\":1070, \"Name\":\"Smith\" },{ \"Id\":1074, \"Name\":\"Jones\" } ]";
let obj = JSON.parse(json);
let list = document.getElementById('servicesList');
let myHTML;

obj.forEach((ObjectRow)=>{
 myHTML += "<li class='sortable-service-item'>" + 
            "<span class='drag-handle-container' data-id='"+ObjectRow["Id"]+"'>" + 
             "<i class='fa fa-bars'></i>" + 
            "</span>";

  Object.keys(ObjectRow).forEach((key)=>{
   myHTML += "<span>"+ObjectRow[key]+"</span>";
  });
 myHTML += "</li>";
});

list.insertAdjacentHTML("beforeEnd" , myHTML);


Share : facebook icon twitter icon
how to split <p><span>Hello</span></p> to <span>Hello</span> using javascript

how to split <p><span>Hello</span></p> to <span>Hello</span> using javascript


By : Donna Fay Bruner
Date : March 29 2020, 07:55 AM
help you fix your problem how to split

Hello

to Hello using javascript , A regular expression that takes care of removing p attributes
code :
var new = text.replace(/^<p[^>]*>(.*)<\/p>$/i, "$1");
var new = text.replace(/^<p.*?>(.*)<\/p>$/i, "$1");
var new = text.replace(/^<p\b.*?>(.*)<\/p>$/i, "$1");
var new = text.replace(/^.*<p\b[^>]*>(.*)<\/p>.*$/i, "$1");
var new = text.replace(/<p\b.*?>/ig, "");
new = text.replace(/<\/p>/ig, "");
Difficulty using javascript replace function with regex for <span> and </span>...all inclusive

Difficulty using javascript replace function with regex for <span> and </span>...all inclusive


By : Bartolly Cékyo
Date : March 29 2020, 07:55 AM
hope this fix your issue In Javascript you need to escape / because JS uses / as regex delimiters and add [^>]* to match anything in span:
code :
.replace(/<\/?span[^>]*>/ig, "")
JavaScript/jQuery RegExp, finding something in a span adding another span around

JavaScript/jQuery RegExp, finding something in a span adding another span around


By : Vlad Madejczyk
Date : March 29 2020, 07:55 AM
I wish this helpful for you You can use regex easily to finding target text. Use .html(function) to change html of element.
code :
$(".s1").html(function(i, html){
    return html.replace(/([$][\d\.]+)/g, "<span class='s2'>$1</span>");
});
.s1 { color: blue }
.s2 { color: red }
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<article class="visible">
    <p class="p1">
        <span class="s1"> Home Fries $2.00</span>
    </p>
</article>
Function to remove <span></span> from string in an json object array in JavaScript

Function to remove <span></span> from string in an json object array in JavaScript


By : latzo
Date : March 29 2020, 07:55 AM
help you fix your problem I know there are many similar questions posted, and have tried a couple solutions, but would really appreciate some guidance with my specific issue. , Try this function. It will remove all markup tags...
code :
function strip(html)
{
   var tmp = document.createElement("DIV");
   tmp.innerHTML = html;
   return tmp.textContent || tmp.innerText || "";
}
var str = '<SPAN CLASS="KEYWORDSEARCHTERM">MOST EMPOWERED</SPAN> COMPANIES 2016';
var expectedText = strip(str);
How to make buttons span mutiple columns/rows with GridPane JavaFX?

How to make buttons span mutiple columns/rows with GridPane JavaFX?


By : Vix. N
Date : March 29 2020, 07:55 AM
This might help you Since you're using a grid pane, you don't really need the HBox and VBox:
code :
import javafx.stage.*;
import javafx.application.*;
import javafx.scene.*;
import javafx.scene.control.*;
import javafx.scene.layout.*;

public class SimpleGUI extends Application {
 public void start(Stage primaryStage) throws Exception {
  GridPane root = new GridPane();
  Scene scene = new Scene(root);

   //Buttons
   Button b1 = new Button("KNAPP 1");
   Button b2 = new Button("KNAPP 2");
   Button b3 = new Button("KNAPP 3");
   Button b4 = new Button("KNAPP 4");
   Button b5 = new Button("KNAPP 5");
   Button b6 = new Button("KNAPP 6");

   root.add(b1, 0, 0);
   root.add(b2, 1, 0);
   root.add(b3, 2, 0);

   root.add(b4, 0, 1);
   root.add(b5, 0, 2);

   // node, columnIndex, rowIndex, columnSpan, rowSpan:
   root.add(b6, 1, 1, 2, 2);

   // allow button to grow:
   b6.setMaxSize(Double.MAX_VALUE, Double.MAX_VALUE);

   primaryStage.setScene(scene);
   primaryStage.show();
 }

 public static void main(String[] args){
  launch(args);
 }
}
Related Posts Related Posts :
  • redux how to use state
  • All data in the db is lost when closing a express based node js server
  • How to convert javascript code for Angular
  • XPath select on child nodes
  • Idle event on mouse move - how to stop script permanently on mouse move
  • Why do I get logic is not defined in this code
  • When I enter a number in the input, the first function starts
  • ES6 imports and node_modules hell
  • How to get css selector of clicked-on element?
  • How to auto input MySQL data (input column 1 data to auto input column 2 data with same column) in php?
  • Appending to Datalist Via Javascript
  • Customizing Material-UI Components with Styled-Components
  • Populate elements with class name using Javascript
  • How to execute promises in batches (first resolving 10, then next 10 and so on)
  • Maximo JS automation script: "importPackage" is not defined
  • How to surround selected text inside textarea with <em> on key combination CTRL+i?
  • Your configured registry does not support audit requests ~ On npm audit
  • What's the Angular equivalent of Vue <slot/>?
  • Iconify icon not updating when "data-icon" set with setAttribute()
  • Javascript newbie stuck with XMLHttpRequest return data
  • How to add obj to to state in my example Redux React
  • Loading "grunt-karma.js" tasks...ERROR >> SyntaxError: Unexpected identifier
  • Why do I get log is not defined
  • get the multiple index of the same string
  • How can I iterate over an Array object by using For IN or FOR OF
  • Launch local executable from web browser
  • How to prepare array of json objects to d3 hierarchical tree structure
  • VueJS - event emitted - show HTML before other calculations
  • Export SASS/SCSS variables to Javascript without exporting them to CSS
  • How to attach an event handler only once continuously
  • How to make button open a link in new tab in JavaScript?
  • Find range from the javascript object
  • How can I use my jQuery code as JavaScript?
  • How to show 5 images in a 2 row slider with bxslider
  • How to convert stream into variables in typescript
  • Three.js custom shader error on Chrome GL_INVALID_OPERATION: Active draw buffers with missing fragment shader outputs
  • My JavaScript doesn't work. How can I solve this problem?
  • Why is this async function is running synchronously?
  • Get updated variable from within react hook before return
  • I want to show all image preview but whenever I upload a new one the old one is gone
  • Would I be able to give access to specific electron APIs safely?
  • Why several clicks fire for each instance of a Class?
  • cant grab value from div using attr()
  • Instantiate subclass without constructing
  • Outputing a created object in javascript to a server side JSON file
  • Transition the numeric labels in a bar chart
  • createBottomTabNavigator: hide just one tab from the tabBar
  • iife vs simple statement behavior with document.title
  • showDialogPopup Refresh Page after Click
  • Child component does not set the initial value passed from the parent: ReactJS
  • Nodejs javascript added to button not responding
  • Trying to define a promise.all
  • Python GEE to extract featurecollection timeseries from Landsat imageries
  • How to write negative binary number?
  • Unable to set property of individual object
  • Why Named Function Expression itself cannot assign Name to another Value?
  • How to reset scroll position on single page pagination
  • How to scroll to bottom of page, when a new message is sent - Socket.io
  • How to reconstruct audio blob from a base64 encoded String?
  • How to calculate numbers within an array of objects
  • shadow
    Privacy Policy - Terms - Contact Us © festivalmusicasacra.org