0

我已经阅读了所有以前的条目以获取两个元素之间的 html/text 节点内容,但它对我不起作用。

我尝试了 jQuery 和纯 javascript 的混合,但又没有。

我正在尝试使用 xml 代码。我无法控制 xml - 它直接来自世界英语圣经 XML。

var xml='<p><v id="1" />In the beginning, God<f caller="+">The Hebrew word rendered “God” is “אֱלֹהִ֑ים” (Elohim).</f> created the heavens and the earth. <ve />'
+'<v id="2" />The earth was formless and empty. Darkness was on the surface of the deep and God’s Spirit was hovering over the surface of the waters. <ve /></p>'
+'<p><v id="3" />God said, “Let there be light,” and there was light. <ve />'
+'<v id="4" />God saw the light, and saw that it was good. God divided the light from the darkness. <ve />'
+'<v id="5" />God called the light “day”, and the darkness he called “night”. There was evening and there was morning, the first day. <ve /></p>';

我需要做的是获取<v>元素和<ve>元素之间的所有 html(文本和 html)并将其包装在 a 中<span>,以便我可以在单个诗句上使用 css。

//original
<v id="1" />In the beginning, God<f caller="+">The Hebrew word rendered “God” is “אֱלֹהִ֑ים” (Elohim).</f> created the heavens and the earth. <ve />
//becomes
<span class=v id=GEN0101>In the beginning, God<f caller="+">The Hebrew word rendered “God” is “אֱלֹהִ֑ים” (Elohim).</f> created the heavens and the earth. </span>

我尝试过使用 jQuery nextUntil(),但它只修改了<f>元素。

var $x=$(xml);
$x.find("v").nextUntil("ve").css('background','red');
$("#content").append($x);

这是我的小提琴:JSFiddle 工作

我已经尝试过纯 javascript,但我也无法让它工作。

var v = xml.getElementsByTagName("ve")[0].previousSibling.textContent;
$("#content").append('<div>'+v+'</div>');

谢谢

4

1 回答 1

0

我能想到的最好的方法是使用 jQuery 的contents()函数。在这里查看小提琴:http: //jsfiddle.net/DKXMx/

于 2013-08-01T15:12:29.293 回答