JSFiddle - React, Tailwind, and code Playground

by kacpaa

HTML

<ul id="HTMLtoBeChanged">
    <li>This is the text inserted by <b>user</b> and styled by him - there should be no comma at the end of a <b><i><u>LI element,</u></i></b></li>
    <li>Here is no comma at the end, so it should <b>stay as it is</b></li>
    <li>And here the comma should <b>dissapear also,</b></li>
</ul>
<button id="remCom">Remove commas</button>
<ul id="CorrectHTML"></ul>

JavaScript

$(function(){
    $('#remCom').on('click', function(){
        $('#CorrectHTML').html('');
        $('li').each(function(){
            var thisText = $(this).text().trim();
            var changedThisText = '';
            if (thisText.slice(-1) == ',') {
           		changedThisText = thisText.slice(0,-1);
            } else {
                changedThisText = thisText;
            }
       		$('#CorrectHTML').append('<li>' + changedThisText + '</li>');
        });    
    });
});