Error access variable form function
-
22-12-2019 - |
Question
In chrome function but in IE10 return error for the variable name in the function, how I can have access to this variable from the function?
$('.kpit').on('click', function() {
var url = $(this).attr('id');
var name = $(this).attr('href');
$('.kpi').html('');
$.post(url, {idKpi: id}, function(result) {
$(name).html(result);
});
});
Solution
Try:
$('.kpit').on('click', function() {
var name = $(this).attr('id');
var element = $(this); //Removed the .attr('href'), as that would store the URL, not the element.
$('.kpi').html('');
$.post(name, {idKpi: id}, function(result) {
$(element).attr('href',result); //Set the HREF by using .attr, not .html
});
});
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow