Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jQuery value passing as a id in html

It is possible to pass a jQuery variable as a Id in Html. For example

 $(document).on('click', '.addvideo', function () {
     var dynamicID = $(this).attr('id');
});

Here I am getting the currently clicked id value "dynamicID". I want pass this value to another variable, like below

$('#'+dynamicID).change(function(){
    alert('hi');
    });

I tried like above. But i am getting error "ReferenceError: dynamicID is not defined". How to resolve this problem ?


1 Answers

Write change event inside addvideo click event, then only it will bind:

$(document).on('click', '.addvideo', function () {
     var dynamicID = $(this).attr('id');
     $('#'+dynamicID).change(function(){
        alert('hi');
     });
});
like image 197
Dhara Parmar Avatar answered Dec 07 '25 02:12

Dhara Parmar



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!