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);
			  }
		  });
	    }
	})
      

Run codeHide result


+3


source to share


3 answers


after trying the code below it works for me.



$('#data_btn').attr('title',returndata);

      

+3


source


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

+3


source


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));

      

0


source







All Articles