• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 462
  • Last Modified:

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.
0
quest_capital
Asked:
quest_capital
  • 4
  • 2
1 Solution
 
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
 
Julian HansenCommented:
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
 
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
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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

Featured Post

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

  • 4
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now