如何获取字符串的内容?

时间:2014-02-26 07:27:26

标签: jquery regex

如果我有

<p>someword here</p>
<span>another thing here</span>new line

这是一个字符串
我如何获得span的内容?

我希望结果是

another thing here
new line

更新:

<script>
var string = "<span>this is span</span>new line";
var anchors = $('<div/>').append(string).find('span').text();
console.log(anchors);
</script>

输出: -

this is span

并希望new line

1 个答案:

答案 0 :(得分:0)

您可以指定一个id或类来跨越和使用jquery

<span class="myclass" id="myid">another thing here</span>

jQuery('#myid').html();

jQuery('.myclass').html();

但是class方法会为你提供所有具有“myclass”类

的元素
相关问题