tags:

views:

24

answers:

4

I have a bunch of Div's on the page

<div id="MainDiv"><div>sometext</div>
<div>sometext</div>
<div>Page 1</div>
<div>Page 1</div>
<div>Page 1</div>
<div id="Placeholder1"></div>
<div>othertext</div>
<div>othertext</div>
<div>Page 2</div>
<div>Page 2</div><div>

How do I hide all child Div's of 'MainDiv' that fall after the div 'Placeholder1'.

Also on a long page, is it possible that once the page loads, the browsers scrolls directly to the Placeholder? Is this possible and is there a cross-browser solution to it?

+1  A: 
$('#Placeholder1 ~ div').hide()

OR

$('#Placeholder1').nextAll('div').hide()

ScrollTo is a plugin that might help you with the second part of your question.

Bobby Jack
thanks bobby..is it possible to hide all controls inside 'MainDiv' after Placeholder1..so not only div but all the controls?
AdamFo
Never mind I got it. I had to use a *
AdamFo
A: 

To auto-scroll to the element just use a hash link (this works in all browsers), for example:

myPage.html#Placeholder1

To hide the divs after it, just just .nextAll() and .hide(), like this:

$("#Placeholder1").nextAll("div").hide();
Nick Craver
Doesn't the ScrollTop as suggested by Chinmayee work cross browser?
AdamFo
@AdamFo - It does, but there's really no need for it, it's already built-into the browsers (for a *very* long time) :)
Nick Craver
Ok but what I do not get is how do I programmatically do it using the myPage.html#Placeholder1 using jquery syntax? On a page load, the scroll has to go down to Placeholder1 and this control has nothing inside it. It is just a placeholder so not visible to the user
AdamFo
@AdamFo - You don't need JavaScript at all, just link to the page with a `#Placeholder1` on the end and it'll scroll down. If you *have* to programmatically do it, just use `location.hash = "Placeholder1";`
Nick Craver
A: 

For hiding all elements after Placeholder1,

$("#Placeholder1").nextAll('div').hide();

and for scrolling

$(document).scrollTop($("#Placeholder1").offset().top)
Chinmayee