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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T16:30:54+00:00 2026-05-26T16:30:54+00:00

I make this code to show and hide p tag depend on the link

  • 0

I make this code to show and hide p tag depend on the link click but what if i have 100 p and links i want an easier way to make it dynamically

<div class="example2">
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Fusce facilisis sagittis lectus. Curabitur quam arcu, adipiscing quis pretium in, pharetra eget dolor.</p>
</div>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js" type="text/javascript"></script>
<script type="text/javascript">
    $(document).ready(function () {
        $('.example2').hide().before('<a href="#" id="toggle-example2" class="button">Open/Close</a>');
        $('a#toggle-example2').click(function () {
            $('.example2').slideToggle(1000);
            return false;
        });
    });
</script>




<div class="example3">
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Fusce facilisis sagittis lectus. Curabitur quam arcu, adipiscing quis pretium in, pharetra eget dolor.</p>
</div>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js" type="text/javascript"></script>
<script type="text/javascript">
    $(document).ready(function () {
        $('.example3').hide().before('<a href="#" id="toggle-example3" class="button">Open/Close</a>');
        $('a#toggle-example3').click(function () {
            $('.example3').slideToggle(1000);
            return false;
        });
    }); 
  • 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-05-26T16:30:55+00:00Added an answer on May 26, 2026 at 4:30 pm

    You can easily traverse via next() to the next element and toggle it.

    <a href="#" class="button">Open/Close</a>    
    <p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Fusce facilisis sagittis lectus. Curabitur quam arcu, adipiscing quis pretium in, pharetra eget dolor.</p>
    
    <a href="#" class="button">Open/Close</a>   
    <p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Fusce facilisis sagittis lectus. Curabitur quam arcu, adipiscing quis pretium in, pharetra eget dolor.</p>
    
    <a href="#" class="button">Open/Close</a>    
    <p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Fusce facilisis sagittis lectus. Curabitur quam arcu, adipiscing quis pretium in, pharetra eget dolor.</p>
    
    
    <script type="text/javascript">
    $(function() {
        $("a.button").click(function(e) {
            $(this).next().slideToggle(1000);
            e.preventDefault();   // way better than 'return false;'
        });
    });
    </script>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have this code to show/hide (toggle) a div when clicking a link: $('#complete-services-link').toggle(
I have this code: $(div#element).hide(fast); $(div#aelement-2).show(fast); How can I make #aelement-2 fade in after
$(document).ready(function(){ $('#content1').hide(); $('a#open').click(function(){ $('#content1').show('slow'); }); $('a#close').click(function(){ $('#content1').hide('slow'); }) }); in this code of toogle
Hi I have been trying to make a show/hide toggle button with jquery but
i've tried using this code and this to make a random quote generator, but
Is it possible to somehow shorten this code: var i=GetStringFromServer('/url'); if(i){ $('#Div1').hide(); $('#Div2').show(); }
I have the following code: $(#submenuSolutions).mouseleave(function () { $(.submenuRightCurrent).hide(); $(.submenuRightCurrent).removeClass(submenuRightCurrent); $(#prasentRight).addClass(submenuRightCurrent); $(#prasentRight).addClass(submenuRightCurrent).stop(true,true).show(); $(.menuHover).removeClass(menuHover); $(this).stop(true,true).hide();
I inherited this code and now need to make modifications. I have a series
I have a toggle button using this code: <script> jQuery(document).ready(function(){ jQuery('#MyToggleSwitch').live('click', function(event) { jQuery('.ElementToHideAndShow').toggle('show');
I have the following snippet of code (see below) and want to make the

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.