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 7914709
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T14:12:33+00:00 2026-06-03T14:12:33+00:00

I am pretty new to jQuery but I am trying to get a code

  • 0

I am pretty new to jQuery but I am trying to get a code setup which hides a div when the ‘innerHTML’ is null. I tried using the code below. But it doesn’t work! Where is my fault??

if (($("#php-errors").html).length) {
    $("#php-errors").css("display", "block");
}
else {
    $("#php-errors").css("display", "none");
}
  • 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-06-03T14:12:34+00:00Added an answer on June 3, 2026 at 2:12 pm

    One line, and using .show() and .hide() methods:

    var hasCont = $("#php-errors").contents().length ? $("#php-errors").show() : $("#php-errors").hide();
    

    Using the ternary operator that says:

    • (define var) statement ?
    • action if statement is true :
    • action if statement is false ;

    DEMO JSFIDDLE


    A good practice would be to cache your element inside a var, let’s call it var $el, and use it like:

    var $el = $("#php-errors");
    var hasCont = $el.contents().length ? $el.show() : $el.hide();
    

    Much more readable, and
    it will save you some micro processing time 😉 but it really helps in terms of cross-function reusability (if defined outside the function.)

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

Sidebar

Related Questions

I'm pretty new to jQuery/JS. But I have loop in jQuery where I would
i'm pretty new to jquery. I'm trying to insert an element to the DOM,
I'm pretty new to jQuery and Greasemonkey, but I want to reform a URL.
I'm pretty new to jQuery... so far I'm impressed. But I encountered a situation
I am pretty new to bootstrap, jquery and client side. I am using the
I'm pretty new to jQuery and just playing around right now. I'm trying to
I'm pretty new to JQuery and JQuery-UI, but I'm having fun with it so
I'm pretty new to the jquery validation plugin. Trying to compare date values in
I'm pretty much new to jquery. I've been trying to do validations where i
I'm pretty new to Jquery and i want to have a hidden div css:

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.