JQuery get id value dinamis

today this jquery get id value from dynamically

Html sample :

<input type="text" id="tag'+data.id+'" value="val.id">
<input type="text" id="tag'+data.id+'" value="val.id">
<input type="text" id="tag'+data.id+'" value="val.id">

Jquery get Id value on event :

$( document ).ready(function() {
 $('input[id^="tag"]').on('click', function() { // even dinamic 
console.log($(this).attr('id')); // get id tag number dinamic
console.log($(this).val()); // get value input onclick dinamic
 });
});
READ :  JSON Decode PHP