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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T14:00:23+00:00 2026-06-18T14:00:23+00:00

I have multiple divs on a page and in a certain div there are

  • 0

I have multiple divs on a page and in a certain div there are more child divs that get floated to go across the page. I want to be able to use javascript to see the width of the window and then divide my set width of the divs to work out how many to display.

I have found the 2 pieces of code. One that measures window width and the other to slice the divs and hide the rest.

$('div').slice(4).hide();



var width = $(window).width();
$(window).resize(function(){
   if($(this).width() != width){
      width = $(this).width();
       console.log(width);
       alert(width);
   }
});

My Problem is how to select only the divs within my speciedfied div. I have tried this but it hasn’t worked. Don’t even know if i’m goin in the right direction

$("#mainContent2").append(('div').slice(4).hide());

Is javascrpt the right way to go about this or would css be able to do what I’m after?

Many Thanks

EDIT: HTML

<div id='mainContent>
<p></p>
<div>
<div id='mainContent2'>
<div><img></img><p></p></div>
<div><img></img><p></p></div>
<div><img></img><p></p></div>
<div><img></img><p></p></div>
<div><img></img><p></p></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-18T14:00:25+00:00Added an answer on June 18, 2026 at 2:00 pm

    If you have got the number of div to show in particular div then you can use this code.

     $(#mainconetent2 > div).slice(4).hide());
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have multiple toggle divs on the same page, and the div I'm toggling
I have a page that is rendered that has multiple divs, all at different
I'm trying to get all the elements on a page which have multiple divs
I have multiple child divs within a parent div. Using CSS , is it
So I have a page that has multiple divs that can be toggled to
I have multiple DIVs in a php page: <?php if ($row['a']!=) { echo <div
I have multiple divs on my page.I want to copy selected text from div1
Okay, I have a page on a Drupal install that has multiple divs. I
I have a page with multiple divs that hold different sections of content. Initially,
I have multiple divs in my page as: <div imageId='image5' name='5' class='speechBubble'> <div imageId='image5'

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.