I want to call a function depending upon the data-value value of the <a>
that is clicked. Is this possible? I tried [call]();
and call();
. Both return errors.
function a() {
alert("Hi");
}
function b() {
alert("Bye");
}
$(function() {
$("a").click(function() {
var call = $(this).attr('data-value');
[call]();
});
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<a data-value="a">A</a>
<a data-value="b">B</a>