Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

BladeRunner's avatar

Getting element id dynamically in Jquery

I have defined an element id in the following way:

id="loanAmmount-{{ $loop->index + 1 }}"

How do I grab the value in Jquery if I know the value part (the number I generate in the loop).

Can I do something like this:

var loanAmmount = $('#loanAmmount-' + value).val();

0 likes
4 replies
tykus's avatar
tykus
Best Answer
Level 104

Yes, you can do that providing you have value defined, the inner expression '#loanAmmount-' + value will be evaluated first.

Are you having a specific problem?

BladeRunner's avatar

Yes I do. This should return value of loanAmmount but it doesn't.

$(".linkPlan").click(function(event) { var value = event.target.id; var loanAmmount = $("#loanAmmount-"+value).val(); console.log(loanAmmount); });

BladeRunner's avatar

$(".linkPlan").click(function(event) {

              var value = event.target.id;

              var loanAmmount = $("#loanAmmount-"+value).val();

              console.log(loanAmmount);
            


      });

Please or to participate in this conversation.