Javascript 从链接上方的span获取文本-Jquery

Javascript 从链接上方的span获取文本-Jquery,javascript,jquery,text,element,closest,Javascript,Jquery,Text,Element,Closest,嗨,我正试图从链接正上方的span元素中获取文本 $(this).closest("span").text() 完整代码: JS $boxes.find('.portlet-header .portlet-maximize').click(function() { // returns the rel of the link fine var widHtml = $(this).attr('rel'); // get text from span above link (not wor

嗨,我正试图从链接正上方的span元素中获取文本

$(this).closest("span").text()
完整代码:

JS

$boxes.find('.portlet-header .portlet-maximize').click(function() {
// returns the rel of the link fine   
var widHtml = $(this).attr('rel'); 
// get text from span above link (not working)
var widTitle = $(this).closest("span").text()
});
HTML

<div class="portlet-header">
<span class="widTitle gmIcon">text I want to get</span>
<a rel="widgets/dashboard/max/goal-mouth" class="portlet-maximize"></a>
</div>

我想要的文本
在祖先树上行走。由于您的
元素是锚的兄弟,而不是祖先,因此您应该使用:


谢谢,这很有道理,但似乎不起作用。但是,这不适用于
$(This).sibbines('.widtile').text()
这应该适用于您问题中的标记。也许您的实际标记不同?
var widTitle = $(this).prev("span").text();