2

all

I want to show hide some ids using jQuery. My html code is

<table>
<tr id="incomplete"></tr>
<tr id="complete"></tr>
<tr id="incomplete"></tr>
<tr id="incomplete"></tr>
<tr id="complete"></tr>
</table>

and jquery code is

<script type="text/javascript">
          jQuery(document).ready(function () {
                          jQuery("#button-entryc").click(function() {


                          jQuery("#incomplete").css("display","none");
                          jQuery("#complete").css("display","table-row");
                      });

                      jQuery("#button-entryi").click(function() {

                          jQuery("#incomplete").css("display","table-row");
                          jQuery("#complete").css("display","none");
                      });
              });
    </script>

But it works for only on id (first id which it finds) Why?

2 Answers 2

7

IDs must be unique, what you can do is use the class attribute and change your # to a .

e.g.

<tr class="incomplete"></tr>
$('.incomplete')
Sign up to request clarification or add additional context in comments.

1 Comment

yes, it should be a class if it's applied to mulitple elements
1

The concept of IDs is to only use them once (so you can refer to one single object). If you want some rules to apply to several elements use classes instead.

Select a class in jQuery by adding the ., just like in CSS:

$('.myClass').click(function(){$(this).css('color','red');});

See: http://www.w3schools.com/css/css_id_class.asp for example

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.