views:

39

answers:

1

This is my HTML page.. If you copy paste this complete HTML in a browser you would see that the second section has Elements and Duration while the third section has Elements and targeted resources, In this case i want to dynamically change the 2nd and 3rd row to expand like the first one.

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
<TITLE> New Document </TITLE>
<META NAME="Generator" CONTENT="EditPlus">
<META NAME="Author" CONTENT="">
<META NAME="Keywords" CONTENT="">
<META NAME="Description" CONTENT="">
<script type="text/javascript" src="jquery-1.4.2.js"></script>
<script type="text/javascript">
  $(document).ready(function(){
  });
  </script>

</script>

</HEAD>

<BODY>
<table border="1">
<tr>

<th class="element_header">Elements1</th>
<th class="tr_res">TR1</th>
<th class="duration">Duration1</th>

</tr>

<tr>

<td class="element_td">Element Data 1</td>
<td class="tr_td">TR - TD - 1</td>
<td class="duration">Duration Data 1</td>

</tr>


<tr>
<th class="element_header">Elements2</th>
<th class="duration">Duration2</th>
</tr>
<tr>
<td class="element_td">Element Data 2</td>
<td class="duration">Duration Data 2</td>
</tr>


<tr>
<th class="element_header">Elements3</th>
<th class="tr_res">TR3</th>

</tr>
<tr>
<td class="element_td">Element Data 3</td>
<td class="tr_td">TR - TD - 3</td>
</tr>
</BODY>
</HTML>
A: 

I would try changing your selector to be based off of the class and not the id. Not good practice to have multiple controls with the same id. Plus jquery only selects a single item when selecting by id.

Also I would check the length property rather than boolean false as jquery will always have an object. So change your checks to be .length > 0.

spinon
Ya.. You are right. I would change my selectors to use class since use of . gives us the total count of tags having element_th and element_td but do you mean the boolean check for targeted resources and duration has to be checked using length as well? It would be geart if you can help me with the psuedo code or may be some real code coz i have been scratching my heads off with this... Thanks !
Yogendra Joshi
Yeah so you would have it look like this:var hasTargetedResources = $(".targeted_resources_header");var hasDuration= $(".duration_header");if(hasTargetedResources.length > 0 || hasDuration.length > 0)So you would obviously adjust the counts to be what according to your logic.Also I'm assuming when you wrote the or statement in that if that it was just pseudo code as or in js is actually ||. Just wanted to mention just in case.
spinon
yeah it was a pseudo code. In JS we have a || condition like this... But the problem still remains, do i need to have a for loop to iterate over all the elements and check if targeted resources and duration exist?
Yogendra Joshi
Not sure I understand what you mean about a for loop. But if you could post the html of a typical page where this problem exists I can see if I can give you the way to apply the fix.
spinon
Hey Brother.. I have just edited the complete HTML in the question part. Can you see that HTML and let me know. I want to write code in the document.ready section of the above HTML THanks brother...
Yogendra Joshi
Ok I have some stuff to do this morning but I will try to take a look soon.
spinon
Alright.. Sure buddy.. Take care till then..
Yogendra Joshi
Hey Spinon, Did you had any luck watching over this problem?
Yogendra Joshi
Sorry I didn't have a chance to look yesterday. Let me take a look now. One question though I thought the td's always had the same class assigned.
spinon