How to set title attribute of a button using jquery
I want to assign ajax return data to the button title attribute on button hover, so I use $('#data_btn').title = html(returndata);
, in the below code, then it cannot show any output. Here #data_btn is the ID of the button element. Please help me.
$('#data_btn').hover(function(){
var val_d = $('#country').val() +"-"+ $('#city').val();
window.alert(val_d);
if(val_d != 0)
{
$.ajax({
type:'post',
url:'getdata.php',
data:{id:val_d},
cache:false,
success: function(returndata){
$('#data_btn').title = html(returndata);
//$('#data_btn').html(returndata);
}
});
}
})
after trying the code below it works for me.
$('#data_btn').attr('title',returndata);
if you want to use $('#data_btn').title = returnData;
, follow these steps: $('#data_btn')[0].title = returnData;
, html()
- undefined The, so just assign returnData in your headline
jsfiddle
You never use .title = html(returndata);
the = sign in jQuery chaining ... Also .title () is not a function.
Use the following:
$('#data_btn').attr('title', $(this).html(returndata));