Reputation: 189
I want to change image height only when its src is not empty with JQuery or JavaScript , i have an image that have fixed height and in chrome they always keep blank place for it even when there is no source for it i want show this height only when image have source
Upvotes: 0
Views: 63
Reputation: 530
You can use
img[src=""] {
display: none;
}
You can change the height or not display it..
Upvotes: 2
Reputation: 667
If you want to use javascript instead of CSS, you can try calling this function whenever you want to check if the image has a source / display the image.
Set an ID for your image and then:
function check()
{
if (document.getElementById("yourimgidhere").src == "")
{
document.getElementById("yourimgidhere").style.display = "none";
}
else
{
document.getElementById("yourimgidhere").style.display = "inline";
}
}
The CSS method is far more effective and is the proper way of doing it as other people have answered, but this should work too.
Upvotes: 2
Reputation: 123397
jQuery is not necessary, just use css to define a zero height for images with an empty src
attribute:
img[src=""] {
height: 0
}
Upvotes: 2