We want to concatenate the function name and variable name. This should occur on click of a <a>
tag.
How can we concatenate the function and variable name?
Issue:
- we are getting error message fn_dataId() is not defined
Desired output:
fn_dataId() should be fn_some123();
What we tried
$(function() {
$('.link').on('click', function() {
console.log('clicked');
var dataId = $(this).attr('data-id');
console.log('data id - ' + dataId);
// What we tried, but didn't work.
fn_dataId();
});
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<a data-id="some123" class="link">
Click here
</a>