每次用戶創建評論時,都會使用帶有prepend
的jQuery添加它。如何使用jQuery刪除commentCross?
我想在某些情況下刪除crossIcon,但它不會被刪除。
that.find(".commentCross").css("display","none");
似乎不是正確的做法。
如何才能從$(this)
中刪除commentCross
?
if ("<%= user %>" != "none") {
var i = 0;
var postKey = "<%= post.key %>";
var commentsRef = firebase.database().ref("comments/"+postKey).orderByChild('commenttimestamp').limitToFirst(25);
commentsRef.once("value", function(snapshot) {
var currentUserUid = firebase.auth().currentUser.uid;
snapshot.forEach(function(childSnapshot){
i++;
if (childSnapshot.val().profilepic == undefined || childSnapshot.val().profilepic == null || childSnapshot.val().profilepic == "") {
$("#commentsBox").prepend("<div class='fullComment' id='"+i+"'><a href='../../users/'"+childSnapshot.val().author+"><div class='userCommentBox'><div class='commentUsername'>"+childSnapshot.val().username+"</div><img class='userPic' src='../../../public/assets/miniProfilePic.png' /></div></a><div class='comment'>"+childSnapshot.val().text+"</div><div><img data-author='"+ childSnapshot.val().author +"' data-post='"+postKey+"' data-comment='"+childSnapshot.key+"'class='commentCross' src='./../../public/assets/cross.png'><img class='replyIcon' data-author='"+ childSnapshot.val().author +"' data-comment='"+childSnapshot.key+"' src='./../../public/assets/replyIcon.png'></div>");
var that = $(this);
var commentAuthor = childSnapshot.val().author;
if (currentUserUid !== commentAuthor) {
that.find(".commentCross").css("display","none");
}
'$(本)'這裏的將是什麼範圍?你可以添加更多有關的代碼? –
爲什麼不直接從'prepend()'中刪除crossIcon的html?並且'我試圖在某些情況下刪除crossIcon'->是什麼情況? –
@AlivetoDie足夠公平,讓我添加更多的上下文 – TheProgrammer