Bir işlevde, html'yi kaldırmaya ve yeni içerik eklemeye çalışmadan önce bir (div, span, p) öğesinde .html öğeleri olup olmadığını kontrol etmem gerekiyor.Kaldırmadan önce öğenin içinde HTML olup olmadığını nasıl kontrol edebilirim? jQuery
Bunun nasıl emin değil ...
Bunu denedim, ama çalışmıyor:
// HERE below I tried to do a check to see if the div's have HTML, but did not work
if ($('.'+rowName+' div').html) {
$('.'+rowName+' div').html.remove();
$('.'+rowName+' span').html.remove();
$('.'+rowName+' p').html.remove();
}
Tam fonksiyon
// Create the Role/Fan rows
function rowMaker (rowName, roleName) {
//alert(rowName+' '+roleName);
// HERE below I tried to do a check to see if the div's have HTML, but did not work
if ($('.'+rowName+' div').html) {
$('.'+rowName+' div').html.remove();
$('.'+rowName+' span').html.remove();
$('.'+rowName+' p').html.remove();
}
// Blue button
$('.'+rowName+' div').append(roleName);
$('.'+rowName+' div').attr('id', 'blue-fan-'+roleName);
var blueButton = ('blue-fan-'+roleName);
console.log('blueButton = '+blueButton);
// Genres
$('.'+rowName+' span').append(roleType);
// Tags
$.each(role_Actor, function(index, item) {
$('.'+rowName+' p').append(item+', ');
});
$('#'+blueButton).click(function() {
console.log('clicked blue button');
// clears the role_Actor to be used to recapture checkboxes
role_Actor = [];
console.log('role_Actor = '+role_Actor);
//$('#modal-'+roleId).modal();
$('#modal-'+roleId).modal({persist:true});
return false;
});
}
Öğeyi kaldırmaya devam ederseniz öğenin HTML'si var mıdır? Neden sadece içeriği ['.html'] (http://api.jquery.com/html) ile tamamen değiştirmiyoruz? –
Oh, bazı şeyler kullanıcı bu düğmeye basacak, işlevi başlatmak ve mavi düğme henüz oluşturulmadı ... bu yüzden konsol kaldırmak ve atmak için herhangi bir .html yok :(belki yerine Yapabileceğim net bir çağrı var mı? Hmm şimdi bakıyor –