我正在尝试获取jQuery中某个链接的兄弟的价值,但我不确定如何选择它。这是我的HTML代码。
<figure>
<a class="figure" href="http://wbond.net/sublime_packages/img/package_control/install_package.png"><img src="http://wbond.net/sublime_packages/img/package_control/install_package.png" title="Something"></a>
<figcaption>
Great Picture Description. Original by <a href="http://www.example.com/">Random person</a>
</figcaption>
</figure>
我想显示figcaption
内figure
的内容。我的实际代码是使用链接中的title
属性。
$(obj).attr('title')
感谢您的支持
答案 0 :(得分:0)
var content = $('figure figcaption').html();
alert(content);
答案 1 :(得分:0)
要回答您的标题,(但不是您的问题),这里是next sibling的选择器:
$('.figure ~ figcaption').
答案 2 :(得分:0)
我假设您要使用figcaption
的内容作为fancybox title
....所以上面使用相同的html
和fancybox v2.x 试试这个脚本:
<script type="text/javascript">
var newCaption;
$(document).ready(function() {
$(".figure").fancybox({
afterLoad: function(){
newCaption = $(this.element).next('figcaption').html();
this.title = newCaption
}
}); // fancybox
}); // ready
</script>
如果您想更改title
类型,请使用helpers
选项,例如
helpers: {
title : {
type : 'inside'
}
}