2016-08-20 7 views
0

は、私はこのような通知ボックスを作成しようとしている:あなたが見たようJS(またはjQuery)でdivに画像を設定するにはどうすればよいですか?

enter image description here

は、非表示コンテンツのロードになり、その上に画像.gifあります。今、私は<div>に次の画像を追加したい:ここ

enter image description here

は私のAjaxコードです:

$(".notifications_list").html(/* add this path: /myfolder/img/progress.gif */); 

$(".notifications_list").html(/* remove progress.gif photo */); 

どのようにすることができます:

function notification(){ 

    $(".notifications_list").html(/* add this path: /myfolder/img/progress.gif */); 

    $.ajax({ 
     url : '/myweb/files/notification.php', 
     dataType : 'JSON', 
     success : function (notification_system) { 

      $(".notifications_list").html(/* remove progress.gif photo */); 

      if(notification_system.success === 1){ 
       $(".notifications_list").html(notification_system.notifications); 

      } else { 
       alert('something is wrong');        
      } 

     } 
    }); 

} 

次の2行に焦点を当ててください。それを行う?つまり、HTMLへのパスで画像を追加して削除するにはどうすればいいですか?

+0

を削除するには、コンテナのdivに画像を付加し、画像Aを与えることができますカスタムCSSクラス/ ID。それを削除したいときは、そのクラス/ idを削除してください。 – Jecoms

答えて

1

お試しください]プリペンド」と '削除' ...

$('.notifications_list').prepend('<img class="your_image" src="http://placekitten.com/100/100">') 

$('.notifications_list .your_image').remove(); 

Demo here...

+0

@MartinAJ問題ありません...あなたのために正しい答えをマークしてください。同じ問題が発生したときに他の人が答えを見つけるのを助けます。 – JasperZelf

関連する問題