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

  • SEARCH
  • Home
  • 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 7582169
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T18:22:15+00:00 2026-05-30T18:22:15+00:00

Having trouble on a simple one. My morning tea isn’t strong enough. IF div

  • 0

Having trouble on a simple one. My morning tea isn’t strong enough.

IF div has a child that’s an anchor THEN- blah. Don’t want to add an additional class to .box

Something like:

$('.box').click(function(){
    if ($(this).children('a')) {
        //some thing
    } else {
        //some thing else
    }
});

<div class="box"><a href="#"><img src="#" /></a></div>
<div class="box"><img src="#" /></div>
<div class="box"><img src="#" /></div>
  • 1 1 Answer
  • 0 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-30T18:22:16+00:00Added an answer on May 30, 2026 at 6:22 pm

    Check the length property:

    $('.box').click(function(){
        if ($(this).children('a').length) {
            //some thing
        } else {
            //some thing else
        }
    });
    

    Since the children method (like most jQuery methods) returns an instance of jQuery, it will always evaluate to true (so you’ll always end up in the if branch). The length property returns a number, which will evaluate to false if it’s 0.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

So this one is probably very simple, but I'm having a bit of trouble
OK, knowledgeable programmer-types, please be gentle... I'm having trouble getting a very simple, one-view
I'm having trouble finding a simple js web UI library that handles styling the
Probably a really simple answer to this one. I am having trouble getting write-progress
I'm having trouble with something that (I think) should be simple, but can't find
I'm having trouble getting jQuery to allow only one content-DIV to be visible at
It seems like it should be simple enough, but im having trouble wrapping my
This probably has a very simple answer, but I'm having trouble figuring it out...
This issue is so deceptively simple that I'm having trouble getting my head around
I've researched many node.js cloud hosts, yet I'm having trouble finding one that suits

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.