JSFiddle - React, Tailwind, and code Playground

HTML

<input id=v value=1234>
<input id=b type=button value=test>
<div id=s></div>

JavaScript

$('#b').click(function(){
    myVar = parseInt($('#v').val(), 10);
    var l = Math.pow(10, Math.floor(Math.log(myVar)/Math.log(10))-1);
    var b = Math.floor(myVar/l);
    var digit = b-Math.floor(b/10)*10;
    $('#s').text('Result : '+digit);
});