hide images without src
Im generating my page content on the serverside and sometimes as reault I have an image without src. Is it p开发者_如何学Cossible to hide all such images using jquery so that ugly icons arent visible for example in chrome ?
thanks for help
You are not supposed to have any <img/>
tags without a src
attribute!
But you can use $('img:not([src]), img[src=""]')
to select images with empty or missing src
attrs.
More complete answer derived from ThiefMaster would be on the following lines
$.each($('img:not([src]), img[src=""]'),function(index, value) {
value.css('display','none');
});
You shouldn't be using JavaScript to hide errors in your markup. Consider people who run with JavaScript disabled, or who use a screen reader.
You don't mention what you're using on the server-side, but surely it's pretty simple in any language to surround the code that outputs the <img>
tag with an IF statement to check if the src
value is blank.
精彩评论