JSFiddle - React, Tailwind, and code Playground

HTML

Text:<input type="text" id="text"/>

<input type="submit" id="submit"/>

<div id="result"></div>


<div id="krotki">fdsgdffdsgdffdsgdffdsgdffdsgdffdsgdffdsgdffdsgdffdsgdffdsgdffdsgdf</div>

JavaScript

$('#submit').on('click', function(){
    
    var text = $('#text').val();
    if(text.length > 15){
        var skrocony = text.substr(0, 15);
        var nowy_temat = skrocony+'...';
        $('#result').append(nowy_temat);
    }else{
        $('#result').append(text);        
    }
    
});

function krotki(text){
    
    if(text.length > 15){
        var skrocony = text.substr(0, 15);
        var nowy_temat = skrocony+'...';
        $('#krotki').text('');
        $('#krotki').append(nowy_temat);    
    }else{
        $('#krotki').text();
    }
    
}

krotki($('#krotki').text());