Obsivus
Obsivus

Reputation: 8359

If the img src is correct add css to the img tag so its display none

I am trying to create a jquery that simply check if there is any img tags with a specific src and if there is any that img should get display: none with css. I want it to iterate throught the page and do it to all img tags

But I cant seem to get it to work.

This is what I tried

$('img([src^="/_layouts/15/images/ikk/news/image.jpg"])').each(function () {
        $(this).css("display", "none");
    });

Html:

<img alt="" src="/_layouts/15/images/ikk/news/image.jpg">

Note: there can be many img tags with this url generated so I need to iterate and check.

Upvotes: 0

Views: 422

Answers (2)

K D
K D

Reputation: 5989

check the working fiddle for it here you have provided a wrong selector.

it should be

$("img[src.....]")

Fiddle

Upvotes: 0

JoDev
JoDev

Reputation: 6873

You make a mistake, don't add () in the first img selector!

$('img[src^="/_layouts/15/images/ikk/news/image.jpg"]').each(function () {
    //$('.latest-news-container img').css("display", "none");
    //and just use
    $(this).hide();
});

And if you just wan't to hide selected img do:

$('img[src^="/_layouts/15/images/ikk/news/image.jpg"]').hide();

Upvotes: 3

Related Questions