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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T03:57:35+00:00 2026-06-17T03:57:35+00:00

i have 2 divs inside foreach loop .first div has information about a company

  • 0

i have 2 divs inside foreach loop .first div has information about a company but shortened form and in second div has full form of information about a company . i want to hide first div and show second div when ‘show more ‘ link of that company has clicked .in my code when i click ‘show more ‘ link and it shows all company not only the company which i clicked .

<?php   
  $X         = 0;
  foreach($companyRows as $row){ ?>
  <div class="first" >
        echo "a company information shortend form"
      </div>
      <div class="second" style="display:none">
       echo "a company information full form"
       </div>
       <a class="show_details"> show more</a>                               
  <?php $X++;
  } ?>

and here is jQuery . i am new in jquery and php.

<script type="text/javascript">
    $(document).ready(function(){
        $(".show_details").click(function(){
            $(".second").show();
            $(".first").hide();
        });
    });
</script>

and want to change show more link to show less.

  • 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-17T03:57:36+00:00Added an answer on June 17, 2026 at 3:57 am

    add a parent <div> in your loop… so that all this html stay inside a parent div.. this way we can use parent()..

    <?php   
      $X         = 0;
       foreach($companyRows as $row){ ?>
       <div class="parentDiv"> //***here****
        <div class="first" >
          echo "a company information shortend form"
        </div>
         <div class="second" style="display:none">
           echo "a company information full form"
         </div>
         <a class="show_details show_more"> show more</a>    //updated 
     </div>                           
    <?php $X++;
    } ?>
    

    JQUERY
    *UPDATED*

    $(document).ready(function(){
        $(".show_details").click(function(){
            var $this=$(this);
            var $parent= $this.parent();
            if($this.hasClass('show_more')){
                $this.removeClass('show_more').addClass('show_less');
    
                $parent.find('.second').show(); //find parent div and div with second class inside that parent div
               $parent.find(".first").hide();
               $this.html('show Less');  // $(this).text('show Less');
            }else if($this.hasClass('show_less')){
                $this.removeClass('show_less').addClass('show_more');
    
                $parent.find('.second').hide(); //find parent div and div with second class inside that parent div
               $parent.find(".first").show();
               $this.html('show More');  // $(this).text('show Less'); 
            } 
        });
    });    
    

    html().. to replace the text inside the clicked link or u can use text()

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

Sidebar

Related Questions

I have two divs inside a wrapper div of width 880px. The first div
I have two divs inside a wrapper-div. The first one is positioned in front
I have 3 divs inside 1 div like so.. <div class=contentImages> <div id=slideshow> <img
I want to append a div inside a div which have many divs inside
I have two MAIN DIVs inside a DIV which is a PART of the
I have two divs one inside another, i would like to overlap one div
So I have 3 divs contained inside a containing div like such: <div id=contain>
I want to have 3 divs aligned inside a container div, something like this:
i have 4 divs inside of a div like this: <div id=Wrapper> <div id=CoreSideBar><!--
I have two DIVs inside one DIV. One of the DIVs is floated left,

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.