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
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");
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With