Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4028768
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T11:15:41+00:00 2026-05-20T11:15:41+00:00

I have multiple containers like this <div class=container> <span> <!– Inside the span is

  • 0

I have multiple containers like this

<div class="container">
    <span>
     <!-- Inside the span is either text or img -->
    </span>
</div>

Goal is to have border around “.container span” only if it contains and image.

i tried something like this.. but it doesnt work

if( $(this).find('.container span img').is(":visible") ){ $(".container span").css({'border':'10px'}); }
  • 1 1 Answer
  • 2 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-20T11:15:42+00:00Added an answer on May 20, 2026 at 11:15 am

    visible is a pseudo selector so it’s

    .is(':visible')
    

    You can also use it like so

    $(this).find('.container span img:visible')
    

    EDIT

    Hey, wait, are you saying that it might not contain an image at all? In that case, you don’t want to be checking for visibility, but rather something like

    $(this).find('.container span img').length > 0
    

    (of course, if there might be images, and they might be hidden, you want to check the length of img:visible)


    EDIT 2

    Now you’ve got a working check as to whether or not there is a visible image. The rest depends on your implementation. I assumed from the use of $(this) that there will be a DOM node of some kind to search within, that’ll only have one .container for each value of this.

    If that’s not the case – if you want to look at all of the DOM in one go – you could go about something like this:

    $('.container span img:visible').each(function() {
        $(this).closest('span').css('border', '10px');
    });
    

    Above, you’re saying that “for all visible images inside a span inside a .container, add a border to their parent spans.

    Another way of doing it would be something like this:

    $('.container span').filter(function() { return $(this).find('img:visible').length > 0; }).css('border', '10px');
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a page that looks something like this: ... <div class=container> <div class=info>
I have a class of multiple 'DIV' elements and inside it are list of
I have this ingredients array which contains multiple variables (like name, icon, value etc.).
I have something like: <div id=container> <div></div> <div></div> <div></div> <div></div> <div></div> <div></div> </div> I've
Let's say I have a situation like so: $(window).load(function() { $(body).append(<div id='container'></div>); var i=1;
I need to format multiple containers (div) in a web page to look like
I have an Html that contains something like: (Multiple divs within div A). <div
I have multiple projects which are to be hosted together in a Tomcat container,
Inside my main folder, I have multiple sub-folders and each sub folder contains multiple
I have a background on an div element with position top. Now this background

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.