Blog Page - How to check if post has image?

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.
6 years ago
Hello gents,

I am currently working on the Blog page and i am curious if it is possible by any chance to set a if statement for the blog post image. Because if you don't have one image, i have a empty DIV block.

I am using Rich Blog Module.

Thanks in advance.

Warm regards,
Galanthus
6 years ago
Galanthus wrote:
Hello gents,

I am currently working on the Blog page and i am curious if it is possible by any chance to set a if statement for the blog post image. Because if you don't have one image, i have a empty DIV block.

I am using Rich Blog Module.

Thanks in advance.

Warm regards,
Galanthus


I think you can get from Regex for doing this.

Go through the link And link. Hope it will helpful for you.
6 years ago
Galanthus wrote:
Hello gents,

I am currently working on the Blog page and i am curious if it is possible by any chance to set a if statement for the blog post image. Because if you don't have one image, i have a empty DIV block.

I am using Rich Blog Module.

Thanks in advance.

Warm regards,
Galanthus


There are several way to do this.

This is only one approach (a quick solution):

$('.YourDivClass div').each(function() {
    if ($(this).find('img').length) {
        // there is an image in this div, do something...
    }
});



This will find an img at any level under the div. If you only want it as a direct descendant, use this for the if condition:

$(this).find('> img').length
This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.