[英]How can I use jquery to move text from multiple elements in order?
我想按順序將文本從多個元素移動到其他元素。 我不想移動元素,只想移動內部文本。 設置基本上是:
<p class='button_text'>Text here.</p>
<p class='button_text'>More text here.</p>
`
<div class="button">Button 1</div> <div class="button">Button 2</div>
我嘗試更改的地方:
var button_text = $('.button_text').html();
$('.button').html(button_text);
產生
<div class="button">Text here.</div>
<div class="button">Text here.</div>
但我希望它產生:
<div class="button">Text here.</div>
<div class="button">More text here.</div>
幫助非常感謝!
您可以先嘗試遍歷p標簽。 喜歡 -
$(document).ready(function(){
var btn = $('.button_text');
var index = 0;
$('.button').each(function(){
$(this).html($(btn[index]).text());
index++;
});
});
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.