関数内でhtmlを削除して新しいコンテンツを追加しようとする前に、a(div、span、p)に.html要素が含まれているかどうかを確認する必要があります。削除する前に要素にHTMLが含まれているかどうかを確認するにはどうすればよいですか? jQuery
これを実行する方法がわからない...
は、私はこれを試みたが、動作していない:
// 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();
}
のフル機能を
// 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;
});
}
要素を削除する場合は、要素にHTMLがあるかどうかは重要ですか?コンテンツを['.html'](http://api.jquery.com/html)で置き換えるだけではどうですか? –
ああ、何らかの理由でユーザーがそのボタンを押すと機能が起動し、青色のボタンがまだ作成されていないので、コンソールに削除してスローしてエラーが表示されることはありません。 hmm今見て –