Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get span title in jquery

Tags:

jquery-ui

I want to retrieve span title in the following html.

<div id="header_customerid_d">
<div>
<span title="This is my span"></span>
</div>
</div>

I have tried with following jquery bt i got "undefined" alert.

var CustomerId = $('#header_customerid_d',this).children("div").children("span").attr("title");
alert(CustomerId);

So please provide me with correct solution.

Thanks, Bharat Mhatre

like image 773
Bharat Mhatre Avatar asked Sep 18 '25 15:09

Bharat Mhatre


1 Answers

var CustomerId = $("#header_customerid_d span").prop("title"); should do the trick. See an example fiddle here.

Note that the prop function is only available in jQuery 1.6+. If you are using an older version of jQuery, use attr instead:

$("#header_customerid_d span").attr("title");
like image 137
James Allardice Avatar answered Sep 21 '25 07:09

James Allardice