I want to assign ajax return data to button's title attribute on hover of button, so i use $('#data_btn').title = html(returndata);
, in below code, then it unable to show any output.
Here, #data_btn is id of button element.
Please help me regarding.
$('#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);
}
});
}
})
I want to assign ajax return data to button's title attribute on hover of button, so i use $('#data_btn').title = html(returndata);
, in below code, then it unable to show any output.
Here, #data_btn is id of button element.
Please help me regarding.
$('#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);
}
});
}
})
Share
Improve this question
edited Apr 28, 2015 at 11:04
Shaunak D
20.6k10 gold badges47 silver badges79 bronze badges
asked Apr 28, 2015 at 10:56
Vijaya SavantVijaya Savant
1354 silver badges19 bronze badges
6
-
1
$('#data_btn').attr('title', html(returndata));
– Rahul Tripathi Commented Apr 28, 2015 at 10:57 - I replaced my code with your, but not working for me. – Vijaya Savant Commented Apr 28, 2015 at 11:02
-
What does
html()
function do? Shouldn't that just be$('#data_btn').attr('title', returndata);
– Shaunak D Commented Apr 28, 2015 at 11:03 -
Are you even getting into
success:
parameter?? – Dhaval Marthak Commented Apr 28, 2015 at 11:03 - Arghhh! It's time for me to learn how to change baby nappies :) Step 1: get nappies. – lshettyl Commented Apr 28, 2015 at 11:06
3 Answers
Reset to default 3if you want to use $('#data_btn').title = returnData;
, do this: $('#data_btn')[0].title = returnData;
, html()
is undefined, so just assign returnData to your title
jsfiddle
by trying below code, it works for me.
$('#data_btn').attr('title',returndata);
You never use .title = html(returndata);
the = sign in a jQuery chain...
also, .title() is not a function.
Use the following:
$('#data_btn').attr('title', $(this).html(returndata));