Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Reduce text inside a button HTML / CSS

In my Javascript I receive a string of 16 characters:

0x67D77Ed8323bF9dA59addF3E34ccC6433c7f3B76

I show this as a button's value, however I would like to show only the first 3-4 digits and the last 2-3 with the dots in the middle, how can I do this?

Example:

0x67D77Ed8323bF9dA59addF3E34ccC6433c7f3B76
-> 0x67D ... 3B76
like image 993
stormy TV Avatar asked Sep 23 '26 09:09

stormy TV


1 Answers

You can use slice method to slice the string and then you can use anywhere you want.

const btn = document.querySelector("button");
const str = "0x67D77Ed8323bF9dA59addF3E34ccC6433c7f3B76";
const result = `${str.slice(0, 5)}...${str.slice(str.length - 4)}`;
console.log(result);

btn.textContent = result;
<button></button>
like image 54
decpk Avatar answered Sep 25 '26 23:09

decpk



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!