如何使用 jQuery 选择没有类或 id 的文本

How to select text that have no class or id using jQuery?

本文关键字:id 文本 何使用 jQuery 选择      更新时间:2023-09-26

我想从下面的html中选择文本,我只想选择这个文本

Adobe Illustrator, Adobe Photoshop

<div class="col-xs-12">
 <h4 class="dl-title">Professional Skills</h4>
 <div class="divider"></div>
Adobe Illustrator, Adobe Photoshop

这是我的代码

$('.col-xs-12:not(.dl-title)').eq(15).text().trim()

我使用 eq(15) 是因为在我要从中获取数据的网站中有很多 .col-xs-12

请帮帮我!提前致谢

请使用这个:

$('.col-xs-12').children().remove().end().text().trim()

当你需要添加任何类或.eq(15)时,然后添加

试试这个

 $(".col-xs-12")
        .clone()    //clone the element
        .children() //select all the children
        .remove()   //remove all the children
        .end()  //again go back to selected element
        .text();

尝试使用 $.parseHTML().html()Array.prototype.pop().textContent

var text = $.parseHTML($(".col-xs-12").eq(15).html()).pop().textContent;

var text = $.parseHTML($(".col-xs-12").html()).pop().textContent;
console.log(text)
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js">
</script>
<div class="col-xs-12">
  <h4 class="dl-title">Professional Skills</h4>
  <div class="divider"></div>
  Adobe Illustrator, Adobe Photoshop
  </div>