Jquery Hide

I have a dynamic table with a toggle show row. When the page loads the sub rows are visiable. How do I make them hidden until I expand them. Here is the code that I am working with.

<script type="text/javascript">
      


        function togglePanelMore(thenext, source) {
    var viewContainer = $(thenext);
 
    if ($(source).html() == "-") {
        $(source).html("+");
        viewContainer.hide();
    }
    else {
        $(source).html("-");
        viewContainer.show();
    }
}
    </script>


<a href="javascript:togglePanelMore('#row<%=i+1%>', '#togglerow<%=i+1%>')" id="togglerow<%=i+1%>">+</a>
garyilmAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

StingRaYCommented:
$(document).ready(function(){
    // define your sub selector here
    var subselector = '[id^="row"]';  // all sub with id starting with "row"
    $(subselector).hide();
});

Open in new window

0
BardobraveCommented:
Add

$(thenext).hide();

At the beginning of your script, this will hide the row by default.
0
ProculopsisCommented:

Is something like this of any use:

<html>
<head>
<title>http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/Q_27482267.html</title>
<meta http-equiv="X-UA-Compatible" content="IE=8" />
<script type="text/javascript" src="http://filedb.experts-exchange.com/incoming/2011/05_w20/458595/jquery-1.5.2.min.js"></script>
<script>

jQuery(document).ready( function() {

  $(".expand").each( function() {
    var group = $(this).attr("group");
    $(this).click( function() {
      $(this).text( ( $(this).text() == "+" )? "-": "+" );
      toggle( group );
    });
    toggle( group );
    $(this).css( {textDecoration: "none"} );
  });

  function toggle( group ) {
    $("tr[rel=" + group).toggle();
  }

});

</script>
</head>

<body>

<table border="1">
<tr><td><a class="expand" href="#" group="group-a">+</a></td><td colspan="2">&larr; toggle rows</td></tr>
<tr rel="group-a"><td></td><td>some</td><td>stuff</td></tr>
<tr rel="group-a"><td></td><td>more</td><td>stuff</td></tr>
<tr rel="group-a"><td></td><td>other</td><td>stuff</td></tr>

<tr><td><a class="expand" href="#" group="group-b">+</a></td><td colspan="2">&larr; toggle rows</td></tr>
<tr rel="group-b"><td></td><td>some</td><td>stuff</td></tr>
<tr rel="group-b"><td></td><td>more</td><td>stuff</td></tr>
<tr rel="group-b"><td></td><td>other</td><td>stuff</td></tr>

<tr><td><a class="expand" href="#" group="group-c">+</a></td><td colspan="2">&larr; toggle rows</td></tr>
<tr rel="group-c"><td></td><td>some</td><td>stuff</td></tr>
<tr rel="group-c"><td></td><td>more</td><td>stuff</td></tr>
<tr rel="group-c"><td></td><td>other</td><td>stuff</td></tr>
</table>

</body>
</html>

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
JavaScript

From novice to tech pro — start learning today.

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.