How to change this javascript code to jQuery specially the string concatination part

Viewed 30

I want to convert this javascript into jQuery but am unable to do so

//JavaScript

var d_Inp = document.getElementById("dollar-input");
var dsign = document.getElementById("dollar-sign");
d_Inp.addEventListener("keyup", () => {
  let len = d_Inp.value.length;

  dsign.style.right = `${len + 3}ch`;
});

//jQuery

$(document).ready(function(){
    $("#dollar-input").keyup(function(){
        let len = $("#dollar-input").val.length;
        $("label").css("right","len+3+ch");
    })
 })

I think I am wrong somewhere $("label").css("right","len + 3ch"); here

1 Answers

In jQuery you need to use val() to get the value of input

 let len = $("#dollar-input").val().length

Then while adding css you directly added string instead of using value from the len

$("label").css("right",len+3+"ch");
Related