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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T19:14:47+00:00 2026-06-11T19:14:47+00:00

Hi I want to hide some divs on my webpage, they contain only script

  • 0

Hi I want to hide some divs on my webpage, they contain only script tags…how do I do that?

for example..

<div>
   <div>
       <div>
        <script type="text/javascript">some js code</script>
       </div>
    <script type="text/javascript">some js code</script>
   </div> 
</div>

basically these divs are empty but they have script tags in it so using empty is not working. Can anyone please suggest how can I remove these divs. My aim is to remove the parent tag itself if there is no value in any of the child.

how can I identify that all the childs are empty for given parent. (I want to check for empty childs and even if it has script I want to ignore that and consider it as empty and finally if all the childs are empty, I want to remove the parent node)

for example consider this…(there can be any number of child, if all are empty then remove the parent)(I want to ignore the script tag and consider that as empty if no value is there other then script tag)

 <div class="printpage">
<div class="flip">
    <div>empty div</div>
    <div>
        <div>
        <div>empty div</div>
            <div>
            <div>empty div</div>
                <div>
                    <script>script</script>
                    <div>empty div</div>
                </div>
            <script>script</script>
            </div>
        </div>
    </div>
</div>
<div class="flip">
    <div>empty div</div>
    <div>
        <div>
        <div>empty div</div>
            <div>
            <div>empty div</div>
                <div>
                    <script>script</script>
                    <div>empty div</div>
                </div>
            <script>script</script>
            </div>
        </div>
    </div>
</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-06-11T19:14:48+00:00Added an answer on June 11, 2026 at 7:14 pm

    EDIT this was harder than it sounds. This is an updated answer following @VisioN’s observation that the script element’s own text wasn’t being ignored.

    This should check whether any element apart from the <script> element contains any text output.

    $('div').each(function() {
        var $this = $(this);
        var $c = $this.contents();
        for (var i = 0, n = $c.length; i < n; ++i) {
            var c = $c.get(i);
            var tag = c.tagName;
            if (tag === 'SCRIPT') continue;                 // ignore script tag
            if (tag === 'IMG' || tag === 'CANVAS') return;  // non-text output
            if ($.trim($(c).text()).length > 0) {           // check text content
                return;
            }
        }
        $this.hide();
    });​
    

    See http://jsfiddle.net/alnitak/PdCnL/

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

Sidebar

Related Questions

<div id=example style=background:yellow;height:200px;width:200px;> <button>Some text</button> </div>​ I want #example to .hide when it's clicked,
I have some divs that I show/hide. I want to reset the forms inside
I have some thumbnails that slideToggle a hidden div. I only want one to
I want hide some fields in existed XML and use that XML as Input
I want to use some buttons to show/hide multiple divs using jquery. The page
I need a js script show / hide with only shown one div at
all I want to show hide some ids using jQuery. My html code is
I want to hide the titlebar for some of my activities. The problem is
I want to hide the titlebar of my app in some of my views.
I want to hide these fieldsets in a Drupal 6 site for some content

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.