Javascript: I need to Loop through some elements

I need to Loop through some table rows elements in order to hide them.
I'm using Jquery to Hide certain rows with the following Jquery code:

$(#S_Name0).hide()

However, I want to hide all rows starting with an ID starting with 'S_' on page load.
How can I loop threw all element  starting with 'S_' to hide.
quest_capitalAsked:
Who is Participating?
 
Julian HansenConnect With a Mentor Commented:
Try this ... (modify to match your html)

...
   $('table tr').each(function() {
      var id = $(this).attr('id');
      if (id.substring(0, 2) == "S_") {
        $(this).hide();
      }
   });

Open in new window

0
 
krishna kishore mellacheruvu venkataCommented:
you can use <DIv> tag  with its attributes for hiding details on page load.
Please find the link below for your reference
http://www.w3schools.com/tags/tag_div.asp
0
 
quest_capitalAuthor Commented:
julianH

I get the error below:


      $('tr').each(function() {
      var id = $(this).attr('id');
      if (id.substring(0, 2) == "S_") {
        Uncaught TypeError: Cannot call method 'substring' of undefined
        $(this).hide();
        }
     });


I'm using:
<script src="js/libs/jquery-1.7.2.min.js" type="text/javascript"></script>

Not sure on the syntax of $('table tr').each...
The table name is 'CashflowGrid'
0
Cloud Class® Course: Amazon Web Services - Basic

Are you thinking about creating an Amazon Web Services account for your business? Not sure where to start? In this course you’ll get an overview of the history of AWS and take a tour of their user interface.

 
quest_capitalAuthor Commented:
julianH

I tried this

$('#CashflowGrid').children("tr").each(function() {
      var id = $(this).attr('id');
      if (id.substring(0, 2) == "S_") {
        $(this).hide();

no error but did not work.
0
 
quest_capitalAuthor Commented:
This worked

$('#CashflowGrid tbody tr').each(function() {
            var id = $(this).attr('id');
            if (id.substring(0, 2) == "S_") {
            $(this).hide();
            }
        });
0
 
quest_capitalAuthor Commented:
...
0
 
Julian HansenCommented:
Sorry was offline - are you sorted?
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.