最初我的div(與按鈕裏面)是隱藏的,當我按下按鈕時,我做了該div的10個克隆。按鈕在div不工作
我希望能夠獨立使用每個按鈕(它們都具有相同的屬性和類)。目前我無法使用任何按鈕。
<div class="search-result">
<h3>Titel(year)</h3>
<button class="btn btn-warning btnFavorite">Favorite</button>
<button id="btnArkiv" class="btn btn-warning btnFAvorite">Arkiv</button>
</div>
$(".btnFavorite").on("click", function(){
alert("hej");
var input = $("#search").val();
saveFavorite(favoriteMovie);
});
克隆div x次的方法。
for(movie in search){
console.log(search[movie].Title);
favoriteMovie = search[movie].Title;
$(".search-result:first").clone().appendTo(".search").find('h3').text(search[movie].Title);
$('#your_element').attr('id','the_new_id');
}
歡迎來到StackOverflow,你的問題應該包含一個最小,完整和可驗證的例子,[這裏是如何](http://stackoverflow.com/help/mcve)。 – hungerstar
去查看_event delegation_。 – CBroe
不要使用輸入類型提交按鈕。除非實際提交表單,否則請使用簡單的