我有一點點困難試圖切換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