获取两个元素之间的文本JQUERY

获取两个元素之间的文本JQUERY,jquery,Jquery,我的应用程序中有以下代码 <div title="Please Click Here to Expand" class="technology3 closedlanguage" headerindex="0h"> <span class="accordprefix"> <img src="http:www.test.com/expanded.gif" style="width:13px; height:13px; margin-Right:20px"> &

我的应用程序中有以下代码

 <div title="Please Click Here to Expand" class="technology3 closedlanguage" headerindex="0h">
<span class="accordprefix">
<img src="http:www.test.com/expanded.gif" style="width:13px; height:13px; margin-Right:20px"> 
</span> 
  Need this text<span class="accordsuffix"></span></div>
但它不起作用。请给出任何建议。

怎么样:

console.log( $('.technology3').text() );
因为它是周围
div
中唯一的文本内容,所以这样做是可行的

$('.technology3).text().trim();

您需要对其调用
trim()
,以清除其周围的垃圾空白。

如果
div.technology3
是多个

$(".accordprefix").each(function(){
    alert($(this).closest('.technology3').text());// get the closest div.technology3 text
});
阅读和

如果
div.technology3
是单一的,那么试试这个

alert($('.technology3').text());
您还可以查看

$.trim($($('.accordprefix')[0].nextSibling).text())
演示:

试试这个:

$('.technology3').text()

我会添加两个标记(只是一个像“~~~~”这样的小字符串)。第一个在
span.accord前缀
之后,第二个在
span.accord后缀
之前。然后我们需要获取
div.technology3
的文本内容,在标记之间找到文本并存储它。然后我们需要移除标记


选中
.after()和.before()

您可以使用jQuery实现这一点

因此,在你的情况下,它将是

$(".accordprefix").nextUntil(".accordsuffix").text().trim()

这将适用于jQuery 1.4以后的版本。

因为它没有包装在特定的对象中,而是在
.prefix
span的父元素中。您可以执行
$(“.accorprefix”).each(函数(){$(this.parent().html();})但是你需要过滤掉所有其他不需要的HTML。你有多个前缀和后缀元素吗?
$("#id_of_first_ele").nextUntil("#id_of_second_ele").text().trim()
$(".accordprefix").nextUntil(".accordsuffix").text().trim()