0
I would like to dynamically change via jQuery the title of a div.
I have the code below, but it doesn’t work. It does the post, returns the correct value. However, with the mouse on top of the div referred to, the title is not changed.
What am I doing wrong?
$(document).on('hover','.buscar_detalhes',function(){
var codigo = $(this).attr('codigo');
$.ajax({
type: "GET",
data: {codigo : codigo},
url: "buscar_detalhes.php",
success: function(resposta){
$(this).attr('title',resposta);
$(this).prop('title',resposta);
}
});
});
<div codigo='123' class='buscar_detalhes'>VER DETALHES</div>
It seems to me that the
$('this')within its functionsuccess, it’s not yours<div>, you can put out an ajaxvar self = $('this')and use this variableselfwithin the functionsuccess– Icaro Martins
Maybe this answer can help, take a look at Some common problems with the
this-- When trying to create an object usingthisthe console says the property is Undefined– Icaro Martins