0

I have <p> tag and in menu

<p>日本刀日本刀日本刀日本刀</p>

but I want wrap text when text over 16 byte

enter image description here

1 Answers1

0

Just using some simple steps: 8 is set for number of characters you want to wrap

var p = $('p'), string = p.text();

if (string.length > 8) {
  var stringToWrap = string.substring(0, 8);
  p.html(string.replace(stringToWrap, '<span>'+ stringToWrap +'</span>'));
}
span {
  font-weight: bold;
  color: red;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<p>日本刀日本刀日本刀日本刀</p>
Sakata Gintoki
  • 1,817
  • 16
  • 23