开发者

How do I detect if an image is a png with jQuery?

开发者 https://www.devze.com 2023-02-03 09:24 出处:网络
I need some way to mar开发者_如何学Gok PNGs with jQuery. Is there any way to do this?In order to select image elements with a png extension in jQuery, you can use attribute selectors.

I need some way to mar开发者_如何学Gok PNGs with jQuery. Is there any way to do this?


In order to select image elements with a png extension in jQuery, you can use attribute selectors.

For your question, you want to match any img element with a src attribute that ends with ($=) .png, so your solution would be $("img[src$='.png']"). If you want to mark those items with a specific class (say, png), you would do: $("img[src$='.png']").addClass('png');

You can use the same style to select elements with any attribute you desire. For instance, to find all anchors with a hash value for the href attribute, you can use: $("a[href^='#']")

jQuery has a big list of different types of selectors, which you can read about here: http://api.jquery.com/category/selectors/

0

精彩评论

暂无评论...
验证码 换一张
取 消