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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T04:34:24+00:00 2026-05-26T04:34:24+00:00

A while ago I used this simple function to hide/unhide divs ‘: $(document).ready(function() {

  • 0

A while ago I used this simple function to hide/unhide divs‘:

$(document).ready(function() {
  $('#job_desc').hide();
  $('#slick-toggle').click(function() {
    $('#job_desc').toggle(400);
    return false;
  });
});

As you can see I’m just hiding the div with the id job_desc when the document is ready, also creating a function that toggles the state of the div when the user clicks on the link with the id slick-toggle.

Well the times change, now I’m generating the div‘s using a php loop like:

while($row = mysql_fetch_array($result, MYSQL_ASSOC)) {
echo '<div id="job_desc['.$row["id_exp"].']">'.$job_desc.'</div>'
}

At this point I’m stuck, I know I need to generate not only the div‘s dynamically but also the toggle buttons for every div.

I really don’t know how to:

  1. Change my jquery function in order to work with dynamically generated div‘s
  2. How to hide all the div‘s when document ready.
  • 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-26T04:34:24+00:00Added an answer on May 26, 2026 at 4:34 am

    You can easily do that by using classes (this is untested but should work):

    while($row = mysql_fetch_assoc($result))
    {
      echo '<div id="job_desc'.$row['id_exp'].'" class="hidable">'.$job_desc.'</div>';
    }
    

    Jquery:

    $(document).ready(function() {
       $('.hidable').hide();
       $('.hidable').click(function() {
        var the_id = $(this).attr('id');
       $('#'+the_id).toggle(400);
      });
    });
    

    EDIT:

    As I said in my comment, I didn’t see the part where you say you want a link tag to toggle the hide/unhide. If it is necessary for your design, you can easily implement the same mechanism and just add a return:false; or event.preventDefault() to avoid the browser following the link; anyway, just give it a class and a (unique) ID, and fetch the latter using the former.

    I spent some minuts thinking to a solution but maybe I don’t understan what you really want. A single that hides/unhides all divs?

    $('.hidable').hide();
    $('a#slick-toggle').click(function(){
      $('.hidable').toggle(400);
      return false;
    }
    

    Or do you want a different link for each div?

    UPDATED:

    Not the most elegant solution, but should work:

    while($row = mysql_fetch_assoc($result))
    {
      echo '<div id="job_desc'.$row['id_exp'].'" class="hidable">'.$job_desc.'<a class="slick-toggle" href="desc'.$row['id_exp'].'">toggle</a></div>';
    }
    

    Jquery:

    $(document).ready(function() {
        $('.hidable').hide(); // hides all divs;
        $('a.slick-toggle').click(function(){
          var the_id = $(this).attr('href');  //gets href
          var div_id = $('#job_' + the_id);  //takes the div id, which is made up with the href
          $(div_id).toggle(400);  //now can match the div
          return false;
        }
    });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i remember a while ago i used a method like this to print out
I have used IPC in Win32 code a while ago - critical sections, events,
A while ago I was trying to figure out a way of doing this
UPDATE 10/19/2010 I know I asked this question a while ago, but the workarounds
As background, I gave an answer to this post a little while ago: Return
A while ago I used a python framework that could control the mouse and
I created a little app a while ago. I created admin.py and used admin.site.register(MenuEntry)
A while ago I used a rails3 plugin that let you type in any
I have question quite much related to this one I asked a while ago
An interviewer used this term with me six months ago and I really didn't

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.