Triggering a jQuery click event to showcase the hidden content

I am attempting to replicate the functionality seen on the website. The issue I am facing is related to the event_content class. I want to display only a limited amount of content initially, and then hide the excess content. Upon clicking the plus class, I would like to reveal all the hidden content.

$(document).ready(function(){
    $(".plus").click(function(){
        alert('hi sudheer');
        $(".event_content").slideDown("slow");
    });
});
.event_profit{
  background: #ecece9;
  width: 100%;
  float: left;
  border-bottom: 2px solid #fff;
  height:180px;
  }  

.plus{
  width:5%;
  margin-top: 5%;
  margin-left: 5%;
}
.event_content p{
margin: 10px 0;
}
.maincontainer{
 width:100%;
 display: -webkit-inline-box;

}
.event_image{
  width: 15%;
  margin-left: 2%;
  margin-top:1%;
}

.event_content{
 width: 70%;
  margin-top: 2%;
  margin-left: 2%;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class="event_profit">

<div class="maincontainer">

<div class="event_image">

<img src="http://www.charitywater.org/blog/../../_files/blog/wp-content/uploads/2015/03/blog-charity-water-thank-you-instameets.png" class="img-circle" style="height:150px;width:150px">

</div>

<div class="event_content">
<p>
</p>
<p>  Angelina Jolie Pitt recently announced that she has had her ovaries and fallopian tubes removed in order to reduce her risk of ovarian cancer. 
 Ms. Jolie Pitt had previous shared that she has a mutation in the BRCA gene, which increases her risk of breast and ovarian cancers. 
 The Alliance received many calls and requests to comment from media outlets; expand this story for links to some of our news coverage.
</p>

</div>

<div class="plus">
<img src="http://www.ovariancancer.org/wp-content/themes/ovariancancer/images/plus2.png" style="width:33px;height:33px;"/>
</div>

</div>


</div>

Answer №1

To make the button work, you can adjust the content's height to a fixed value and then use jQuery to animate it to 'auto' on click. It seems like the jQuery code may be missing from the snippet.

$(document).ready(function(){
    $(".plus").click(function(){
        alert('hi sudheer');
        $(".event_content").css({ 'height' : 'auto' });
    });
});
.event_profit{
  background: #ecece9;
  width: 100%;
  float: left;
  border-bottom: 2px solid #fff;
  height:180px;
  }  

.plus{
  width:5%;
  margin-top: 5%;
  margin-left: 5%;
}
.event_content p{
margin: 10px 0;
}
.maincontainer{
 width:100%;
 display: -webkit-inline-box;

}
.event_image{
  width: 15%;
  margin-left: 2%;
  margin-top:1%;
}

.event_content{
 width: 70%;
  margin-top: 2%;
  margin-left: 2%;
  height: 47px;
  overflow: hidden;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class="event_profit">

<div class="maincontainer">

<div class="event_image">

<img src="http://www.charitywater.org/blog/../../_files/blog/wp-content/uploads/2015/03/blog-charity-water-thank-you-instameets.png" class="img-circle" style="height:150px;width:150px">

</div>

<div class="event_content">
<p>
</p>
<p>  Angelina Jolie Pitt recently announced that she has had her ovaries and fallopian tubes removed in order to reduce her risk of ovarian cancer. 
 Ms. Jolie Pitt had previous shared that she has a mutation in the BRCA gene, which increases her risk of breast and ovarian cancers. 
 The Alliance received many calls and requests to comment from media outlets; expand this story for links to some of our news coverage.
</p>

</div>

<div class="plus">
<img src="http://www.ovariancancer.org/wp-content/themes/ovariancancer/images/plus2.png" style="width:33px;height:33px;"/>
</div>

</div>


</div>

Answer №2

Include an additional div to display the full summary

HTML

<div class="event_profit">

    <div class="maincontainer">

        <div class="event_image">

        <img src="http://www.charitywater.org/blog/../../_files/blog/wp-content/uploads/2015/03/blog-charity-water-thank-you-instameets.png" class="img-circle" style="height:150px;width:150px">

        </div>

        <div class="event_content" >
            <p>
            </p>
            <p>  Angelina Jolie Pitt recently revealed that she underwent surgery to reduce her risk of ovarian cancer. 
                 She has a mutation in the BRCA gene, increasing her susceptibility to breast and ovarian cancers. 
                 The Alliance received numerous media requests for comments on this topic.
            </p>

        </div>

        <div class="plus">
            <img src="http://www.ovariancancer.org/wp-content/themes/ovariancancer/images/plus2.png" style="width:33px;height:33px;"/>
        </div>

    </div;
  <div class="extraContent" style="display:none">
                    <p>  Angelina Jolie Pitt recently announced that she had surgery to reduce her risk of ovarian cancer. 
                 She carries a BRCA gene mutation, increasing her chances of breast and ovarian cancers. 
                 Numerous media outlets sought comments from The Alliance; visit our news coverage links for more details.
            </p>
            </div>


</div>

CSS

.event_profit,.extraContent{
  background: #ecece9;
  width: 100%;
  float: left;
  border-bottom: 2px solid #fff;
  height:180px;
  }  

.plus{
  width:5%;
  margin-top: 5%;
  margin-left: 5%;
}
.event_content p{
    margin: 10px 0;
}
.maincontainer{
 width:100%;
 display: -webkit-inline-box;

}
.event_image{
  width: 15%;
  margin-left: 2%;
  margin-top:1%;
}

.event_content{
 width: 70%;
  margin-top: 2%;
  margin-left: 2%;
}

JavaScript

$(document).ready(function(){
    $(".plus").click(function(){

        $(".extraContent").slideDown("slow");
    });
});

DEMO

Answer №3

Below is the code snippet showcasing how jQuery is used to display and hide a div element:

jQuery( document ).ready(function() {
    jQuery(".plus").click(function() 
    {

        jQuery( this).parent().toggleClass( "open" );
        jQuery( this).parent().find('.secret').toggle("slow");
        //jQuery(".secret", this).toggle("slow");
   });

});

http://jsfiddle.net/0g35mot8/1/

Answer №4

This solution will meet your requirements

#Check out the live demo#

Using Jquery :

jQuery( document ).ready(function() {
    jQuery(".plus").click(function() 
    {

        jQuery( this).parent().toggleClass( "open" );
        jQuery( this).parent().find('.secret').toggle("slow");

   });

});

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

converting a JSON object into an array

I'm facing a challenge and unsure how to proceed. I have received JSON data from an API: https://i.stack.imgur.com/GdDUo.png When I log the data, this is what appears in the console: https://i.stack.imgur.com/GjSPW.png My goal is to extract the id ...

What is the best way to add styling to my image when hovered over within a link on a responsive website?

I'm having trouble aligning the :hover state with the original footer image links. Here is an edited version of the flicker issue I encountered on Chrome, while nothing appeared on Safari. https://i.sstatic.net/ExdPW.png I apologize for linking to ...

What are the best ways to keep a django page up to date without the need for manual

Currently, I am in the process of developing a Django website focused on the stock market. Utilizing an API, I am pulling real-time data from the stock market and aiming to update the live price of a stock every 5 seconds according to the information pro ...

Using createStyles in TypeScript to align content with justifyContent

Within my toolbar, I have two icons positioned on the left end. At the moment, I am applying this specific styling approach: const useStyles = makeStyles((theme: Theme) => createStyles({ root: { display: 'flex', }, appBar: ...

Unexpected updates occurring in custom Google Sheet functions

Currently, I am utilizing a personalized function to retrieve price data for EVE Online. However, I am encountering an issue where the function is updating every 10-20 minutes, leading to a depletion of my daily URL Fetches quota. The primary function can ...

Generating variables dynamically within a React Native component

In my React Native component, I need to create a variable that will be used multiple times. Each instance of this component should have a different variable name for reference. <View ref={view => { shapeView = view; }} onLayout={({ nativeE ...

Bringing Angular ECharts into a Stackblitz 15.1 setup: A How-To Guide

Recently, Stackblitz made a change to use a standalone configuration for Angular Projects. However, when trying to initialize the module for Angular ECharts (ngx-echarts), an error occurred: Error in src/main.ts (18:5) Type 'ModuleWithProviders<Ngx ...

It is not possible for $_GET to loop through an array

I have a list of values called dataId obtained from checkbox selections, and I want to send it via a GET AJAX request: dataId = 1, 2, 16, 15, 17, 3, 14, 5, 9, 11; URI = "<?php echo site_url('Terpasang/Update_Kebutuhan_ke_Terpasang')?>"; $. ...

Ensure that the body background image remains stretched and perfectly centered regardless of the screen resolution

I am having an issue with vertical centering on a website I created. Everything looks fine on my monitor, but at higher resolutions, the tables don't align in the center and the image shrinks. How can I ensure that everything stays aligned properly? ...

Encountering an issue while updating information following the migration to vue-chartjs 4

I recently upgraded from vue-chartjs version 3 to version 4. I successfully migrated my LineChart component by updating the template section and removing the draw method calls. This component is utilized for two separate charts. However, when I close the ...

The generation of the npm bin script is not working as expected on Windows operating systems

I'm working on developing an NPM package for command line use. I've set up npm's bin in my package.json to specify the JS file to be executed. Here is a snippet from my package.json: "name": "textree", "bin": { "textree": "./src/cli.js" ...

Is there a way for me to position my chat messages on the right side in the chat room?

I have a react chat application and I'm looking to customize the appearance of my messages. Currently, all entries with an orange vertical bar belong to me and are displayed on the left side of the chat room. I would like to move them to the right sid ...

how to enable drag and drop functionality based on names in angularjs

In my project using angular js, I have implemented a drag and drop feature that allows items to be dragged between cells in two directions. I now want to enhance this functionality by allowing members with 'a's (e.g. 1a, 2a, etc.) to be dragged ...

Is there a way to cancel a fetch request and initiate a new one right away?

Below is an illustration taken from MDN. The example showcases two buttons - one for sending a request and the other for canceling it. var controller = new AbortController(); var signal = controller.signal; var downloadBtn = document.querySelector(&apos ...

Creating a reusable field for reactive forms in Angular: A step-by-step guide

I need assistance with creating a versatile field component for reactive forms, but I am facing challenges in retrieving the value from the custom-input element. <form [formGroup]="form" (ngSubmit)="submit()"> <custom-input i ...

Issues arising when checking the responsiveness of the navigation bar on display

Recently, I encountered an issue with the navigation bar on my webpage. It contains an image logo on the left and three links on the right. The problem arises when I test the responsiveness using different devices on Chrome; the navigation bar resizes and ...

Populate your website with both a Bootstrap Popover and Modal for interactive user engagement through hover

Here's the situation: I want to showcase a user's name with a popover that reveals a snippet of their profile information. I've got that part down, where it dynamically generates and displays the popover content as needed. The popover functi ...

A Sweet Alert to Deliver your Morning Toasty Message

I seem to be encountering an issue with my toast message. Instead of the toast popping up immediately after submitting the form, it keeps appearing even if I haven't submitted the form and even when navigating from another page to this one, the toast ...

After the AJAX request, $this experienced a loss of focus

I am facing an issue with my CakePHP code snippet below: <tr class="tr_clone"> <td><?php echo $this->Form->input('items][',array('label'=>false,'options'=>$items,'class'=>'it ...

Creating a larger spinning div using CSS3 animation

I am looking to add a fun hover effect to my div where it spins and zooms in at the same time. Here is what I have so far: [html] div class="myMsg">> <p id="welly" style="color: #009">Welcome to Y3!<br><br><br>T ...