按下按钮时,我想制作<div class="search-result">
的新副本并更改其中的h3。
我试图克隆它,但那只会克隆已经组成的那个,我不知道如何在新的克隆版本中更改h3的值。
在$(".search-result").clone().appendTo(".search");
中如何更改我刚刚克隆的值的值,因为我有一个循环来制作更多这些?
还有其他方法吗?
<div class="col-xs-12 col-md-6 search" style="background-color: blue;">
<h2>Sök resultat</h2>
<div class="search-result">
<h3>Titel(year)</h3>
<input id="btnFavorite" type="submit" value="Favoritfilm" class="btn btn-warning">
<input id="btnArkiv" type="submit" value="Arkiv" class="btn btn-warning">
</div>
</div>
答案 0 :(得分:0)
尝试这样的事情。在此示例中,您首先需要使用cloneNode
克隆节点,然后将其附加到父div。
使用find()
在克隆的div中找到h3标记,并使用html()
来操作h3标记的内部html。
can = document.getElementById(".search_result")
clone = can.cloneNode(".search_result");
document.getElementById(".search").appendChild(clone);
clone.find('h3').html( 'put new value here' );