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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T15:40:47+00:00 2026-06-05T15:40:47+00:00

I got following repeating syntax and I want to keep all <h1> that is

  • 0

I got following repeating syntax and I want to keep all <h1> that is followed by at least one not hidden div, but remove the remaining orphaned <h1>:

<h1>FIRST</h1>
<div></div>
<div></div>

<h1>SECOND</h1>
<div style="display:none"></div>
<div></div>

<h1>THIRD</h1>
<div style="display:none"></div>
<div style="display:none"></div>

<h1>FOURTH</h1>
<div></div>
<div></div>

As you can see, sometimes there is a div preceding the <h1> that isn’t hidden. So in the third block I want to hide the <h1>, but not in the second one or any other one.

What I tried is basically searching for a case where an <h1> is followed by another <h1> while ignoring all the hidden elements in between:

$('h1').each(function(){
    if($(this).nextAll().not(':hidden') == $('h1')) { $(this).hide() }
})

Unfortunately it won’t hide any of the <h1> and I just can’t figure out why, although I suspect the :hidden attribute being the problem. It should be noted that in my real code the hidden <div> is not hidden by ‘display:none’, but by using jQuerys .hide()!

Hope someone can help out.

  • 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-05T15:40:48+00:00Added an answer on June 5, 2026 at 3:40 pm

    the most clean solution i can think of:

    $('h1').each(function(){
      if ( $(this).nextUntil('h1').not(':hidden').length == 0 ) $(this).hide();
    });​
    

    example here: http://jsfiddle.net/sagivo/sTveD/

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

Sidebar

Related Questions

I've got the following code that works OK, but I'm not sure if I
[Meta notes: the following question is not answered, but the problem that the question
I got following error... System.NullReferenceException: Object reference not set to an instance of an
I got following code from net and it looks everything is proper but i'm
I've got following code in my AsyncTask. The only thing I want the AsyncTask
I've got following URL in symfony (specifics not important): /frontend_dev.php/something/25/apple ... and a routing
Okay I got the following class, but item is always null when I GetIstance();
I've got a report that works perfectly in development previews. But when I deploy
I've got a question but to get an answer the following fact has first
I ve got the following reg exp (-[^\w+])|([\w+]-[\w+]) I want to use it to

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.