0

I have a helpSection that is displayed by default. When the user searches for results, the page reloads and the searchResults should be displayed where the help section is located and the help section set to display:none.

I would like to have some jQuery that searches the page and determines if the helpSection is on the screen or not. If the searchResults are being displayed, the helpSection should disappear.

I have tried various methods and none of them worked. Any help would be greatly appreciated.

3
  • 1
    can you post your markup and what you have treid? Commented Jul 17, 2013 at 18:37
  • Wouldn't it be better so use server side script to determine what to display based on search params? Commented Jul 17, 2013 at 18:39
  • 1
    Show some of what you have tried, then we will be able to better help you. Commented Jul 17, 2013 at 18:52

3 Answers 3

1

Like this :

if($('#yourElement').is(':visible')) { $('#yourOtherElement').hide(); } 

If you want to show it instead, you can use show(), like this :

$('#yourOtherElement').show(); 

However, if this is something that is determined on page load, it would be smarter to define this using your server-side language.

Sign up to request clarification or add additional context in comments.

1 Comment

He want's to hide the div.
0

It seems that you have only one help section on your page.

Imperative approach: So you could solve this problem by using getElementById to retreive your help section element. If you don't get an element returned it's not appended to the dom, otherwise check the display attribute.

Event based approach (check browser restrictions): If you just remove and append the help section to the dom on demand you could bind dom insertion and removal to trigger the visibility of the other element. Here is a related post where the event binding is discussed Is there a jquery event that fires when a new node is inserted into the dom?

Comments

0

Depending on your HTML markup, you could possibly do it with CSS only.

CSS

#searchResults + #helpSection { display: none; } 

HTML

<div id="searchResults">Search search search</div> <div id="helpSection">Help help help</div> 

On jsfiddle

See what happens when you remove:

<div id="searchResults">Search search search</div> 

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.