How do you open two div's at once with one click

Hi, I am really close thanks to you guys!!

I need to be able to open and close two div's at once based on one click.  I think I would have it if I could take out one of the "[+] Dates and Locations" on each row and have the remaining one open and close the two div's:

Here is what I have so far (thanks leakim971)


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script>
<script type="text/javascript">
$(document).ready(function () {
    $("#toggle_all_dates").on('click', function () {
        var isShowingAll = $(this).hasClass('showAll');
        var anchors = $("#dates_list li a");
        anchors[ isShowingAll ? "removeClass" : "addClass" ]("open");
        $(this).toggleClass('showAll');
        toggleDate(anchors, isShowingAll);
        $(this).html( isShowingAll ? 'Show all  Dates and Locations' : 'Hide all Dates and Locations' );
    });    
    
    /*
    $("#dates_list li a").on('click', function () {
        var mOpen = $(this).hasClass("open");
        $(this).toggleClass("open");
        toggleDate($(this), mOpen);        
    });
    */

    $("#dates_list li a").on('click', function () {
        var mOpen = $(this).hasClass("open");
        var anchors = $(this).closest("tr").find("li a");
        anchors[ mOpen ? "removeClass" : "addClass" ]("open");
        toggleDate(anchors, mOpen);        
    });
    
    function toggleDate($elem, isOpen){
        $elem.each(function() {
            $(this).html( isOpen ? '[+] Dates and Locations' : '[-] Dates and Locations');
            $(this).next()[ isOpen ? "slideUp" : "slideDown" ]();
        });
    }
});
</script>
<style>ul#dates_list{
    list-style-type: none;
    margin: 0;
    padding: 0;
}
ul#dates_list a{
    cursor: pointer;
}
ul#dates_list div.moredates {
    display: none;
} 
</style>
</head>

<body>
<a id="toggle_all_dates" class="moredates">Show all Dates and Locations</a>

<ul id="dates_list">
<table id="mytable">
<tr>
<td>
    <li>
        <a class="moredates">[+]Dates and Locations Row One</a>
        <div class="moredates" data-collapsed="true">More dates one...</div>
      
    </li>
    </td>
    <td>
    <li>
        <a>[+]Dates and Locations Row One</a>
        <div class="moredates" data-collapsed="true">More Locations two...</div> 
    </li>
    </td>
</tr>
<tr>
<td>
    <li>
        <a class="moredates">[+]Dates and Locations Row Two</a>
        <div class="moredates" data-collapsed="true">More dates one...</div>
      
    </li>
    </td>
    <td>
    <li>
        <a>[+]Dates and Locations Row Two</a>
        <div class="moredates" data-collapsed="true">More Locations two...</div> 
    </li>
    </td>
</tr>
</table>
</ul>
</body>
</html>

Open in new window

smfmetro10Asked:
Who is Participating?
 
RobConnect With a Mentor Owner (Aidellio)Commented:
Ok,

I've just modified it slightly to exclude any anchors that are blank

http://jsbin.com/EGoHObu/4/edit?html,js,output

function toggleDate($elem, isOpen){
    $elem.each(function() {
      if ($(this).html() !== "") {
        $(this).html( isOpen ? '[+] Dates and Locations' : '[-] Dates and Locations');
      }
      $(this).next()[ isOpen ? "slideUp" : "slideDown" ]();
    });
  }

Open in new window

0
 
Scott Fell, EE MVEDeveloper & EE ModeratorCommented:
I don't see anything happening so far http://jsbin.com/EGoHObu/1/edit?html,output  Do you get something different?
0
 
RobOwner (Aidellio)Commented:
That jsbin works for me Scott...Opens both divs?
0
Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

 
smfmetro10Author Commented:
Yes!! Thanks!
Is it possible to only have one "[+] Dates and Locations" per row (but both div's open)?
0
 
RobOwner (Aidellio)Commented:
Hows that going to work?  Assume the numbers below are each [+] Dates and Locations .  If you click on 1 does is open 2?  what happens when you click on 2 does it open 3 or 1?

1
2
3
4
5
6
0
 
smfmetro10Author Commented:
I would like it to function the way it does now but with only one "[+] Dates and Locations" per row. Right now there are two of them but I can't figure out how to take one out and have it open both div's in the row
0
 
RobOwner (Aidellio)Commented:
Sorry I'm confused you want only one per row but open two on a row... Just not making any sense to me. What am I missing ?
0
 
smfmetro10Author Commented:
Sorry for not being able to better clarify.

Right now there are two "[+] Dates and Locations" per row. If you click either one of them, it opens both div's on the row. I would just like there to be only one place where you can click to open up both div's per row...

I attached some screen shots for better clarification.

Make sense?

Thanks for the help!
image1.png
image2.png
0
 
RobOwner (Aidellio)Commented:
Thanks for the explanation - it seems a lot clearer but rather than trying to force this to work, is it a possibility to restructure your html?

eg remove the table completely and use css to layout your content.
0
 
smfmetro10Author Commented:
No, The table is holding data from a database that you can click on the headers of the table to sort alphabetically and by date and by type.
0
 
smfmetro10Author Commented:
Great- Thank You!  The "Show all / Hide all dates and locations" is a bit clunky.

When you open the individual div's you have to cycle through the "Show all/Hide All..." to get it to be correct, but I can take it from here.

Thanks again!!
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.