jquery – Locate a control and hide elements – Education Career Blog

I have a bunch of Div’s on the page

<div id="MainDiv"><div>sometext</div>
<div>Page 1</div>
<div>Page 1</div>
<div>Page 1</div>
<div id="Placeholder1"></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?


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



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


For hiding all elements after Placeholder1,


and for scrolling



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


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


Leave a Comment