I have a simple list that is created by a list of checkboxes. Generated code is easy
white,blue,red,black
I need to use jquery to wrap each of these elements in an <li> tag. How do you view a list and use a comma as a separator? I will also need to remove the comma. Sometimes there will be 1 element, sometimes 3, etc.
Thanks in advance!
<script type="text/javascript"> var mystring = 'white,blue,red,black'; mystring = '<ul><li>' + mystring.replace(/,/gi,'</li><li>') + '</li></ul>'; document.write(mystring); </script>
Outputs:
<ul> <li>white</li> <li>blue</li> <li>red</li> <li>black</li> </ul>
It does not use jquery at all :)
var el = $('#elementSelector'); var values = el.html().split(','); el.html('<ul>' + $.map(values, function(v) { return '<li>' + v + '</li>'; }).join('') + '</ul>');
lol, 1 omfgroflmao: D jquery goodiness
omfgroflmao
mystring = '<ul>' + mystring.replace(/(\w+),?/g, '<li>$1</li>') + '</ul>';
jquery 1 .. -
myobject = $('<ul>').append(mystring.replace(/(\w+),?/g, '<li>$1</li>'));
var final_string = "<ul><li>" + myString.replace(/,/gi, '</li><li>') + "</li></ul>";
Source: https://habr.com/ru/post/1740086/More articles:Placing a built-in Google map marker with Selenium - seleniumUsing a function that may not match all the values in a list - haskellProblem converts column values from VARCHAR (n) to DECIMAL - sql-serverC Selection of two-dimensional arrays - cHow to change this code in C ++ to make work better - c ++Does jquery create a complex histogram with a fleet? - jqueryКак отобразить подтверждение, которое не удалось выполнить в моем Rails unit test? - ruby-on-railsto lock a file so that it is not deleted - c ++What is a linked cursor list? [C ++] - c ++https://translate.googleusercontent.com/translate_c?depth=1&pto=aue&rurl=translate.google.com&sl=ru&sp=nmt4&tl=en&u=https://fooobar.com/questions/1740091/connecting-multiple-buttons-to-one-action&usg=ALkJrhhz9x0x_dMRuBm2gvcmHHKHMOFVdwAll Articles