Getting title attribute with jQuery
assume that I have this list:开发者_如何学编程
<ul id="carousel">
<li><a title="hey"><img src="image.png"/></a></li>
</div>
And now my jQuery script:
$(function() {
$("#carousel a").click(function(){
var url = $(this).attr('title');
alert(url);
});
});
This doesn't work, it works for other attributes such as "alt", "rel" etc. I will be greatful for any assistance.
Works for me in Safari 4 on Mac OS X. What browser are you using? Does the example I linked to fail for you?
Your example is perfect (because I did try it and it works) , if you using IE8 try to cleare the cache.
I believe it will not work in Firefox because of your invalid markup (as seen in Brian Campbell's link). IE8 seems to work fine following the same link. It would seem that IE8 does not care about closing the <ul>
.
精彩评论