我有一点点困难试图切换2个元素周围的JQuery时,他们是在一个字符串变量。jquery切换元素,虽然他们在一个变量内
如:
var myString =
"<div class='chatMessage'>Something here
<div class='test'>My test</div>
<div class='anotherTest'> the other test</div>
Something there
</div>";
我想是围绕切换两个班,制作“anotherTest”是盈方的“测试”。
我试过到目前为止是:
var myString =
"<div class='chatMessage'>Something here
<div class='test'>My test</div>
<div class='anotherTest'> the other test</div>
Something there
</div>";
var div1 = myString.filter('.test');
var div2 = myString.filter('.anotherTest');
var tdiv1 = div1.clone();
var tdiv2 = div2.clone();
myMessage = div1.replaceWith(tdiv2);
myMessage = div2.replaceWith(tdiv1);
不过,我收到以下错误
t.replace is not a function
我不知道我怎么会能够实现切换两个div左右,而仍然存储在变量中,然后再显示给用户?
不是应该变种DIV1 = myString.filter( '试验'); ? – CaptainHere
为什么你想在字符串中切换它们? –
我的代码中没有看到“t”或“.replace”。 – evolutionxbox