2014-02-08 86 views
4

我有一個包含大量圖像的頁面。我只想隱藏這些圖片,如果它們是gif。用jquery檢測.gif

這是結構:

<div class="wrapper"> 
    <div class="entry"> 
    <div class="image"><img src="imagefile.png" /> </div> 
    </div> 
    <div class="entry"> 
    <div class="image"><img src="imagefile.gif" /> </div> 
    </div> 
</div> 

我可以過濾所有的圖片是這樣的:

$('.image').closest('.entry').not(".hidewrapper").wrap("<div class='hidewrapper' style=\"display:none\"></div>").closest('.entry').prepend("<a href=\"#\" class=\"unhideImage\" >show me</a>"); 

由於該網站有大量的圖片:有沒有辦法來篩選只有.gif - 沒有for循環的文件?還是我完全錯誤,循環需要比單線更多的性能?

+0

像' 「IMG [來源$ = GIF]」'或者你可以生成頁面的時候添加一些類'用GIF img',例如'

+0

謝謝。第二個將無法正常工作,因爲我無法訪問源代碼,但操縱外部網站(Chrome擴展) –

回答

4

你可以檢測到它,

$('div.image img[src$=".gif"]') 

請仔細閱讀here更多地瞭解attribute ends with selector