Click here to Skip to main content
15,915,513 members
Please Sign up or sign in to vote.
1.24/5 (3 votes)
HTML
<table>
<tr>
<td class="test">
   <div>
       <div class="halo">

       </div>
   </div>
</td>
<td class="test">
   <div>
       <div class="hai">

       </div>
   </div>
</td>
</tr>
</table>


i like to change css class of td "test" to "done" if div class is halo.

What I have tried:

HTML
<table>
<tr>
<td class="test">
   <div>
       <div class="halo">

       </div>
   </div>
</td>
<td class="test">
   <div>
       <div class="hai">

       </div>
   </div>
</td>
</tr>
</table>
Posted
Updated 15-May-16 3:40am
v4
Comments
Karthik_Mahalingam 15-May-16 2:52am    
your question incomplete, provide more info..

using javascript ?
Kornfeld Eliyahu Peter 15-May-16 2:56am    
Read a book about HTML/CSS, maybe here: http://www.codeproject.com/Learn/HTML/
Kochathu Thomas Tinu 15-May-16 2:56am    
using javascript
Karthik_Mahalingam 15-May-16 3:00am    
always use Reply button, else the user wont get notified.
Karthik_Mahalingam 15-May-16 9:39am    
its ok
provide more info by using improve question button

1 solution

You could do something like this:
HTML
<!DOCTYPE html>
<html>
	<head>
		<title>Change HTML class</title>
		
		<style>
			.test p
			{
				color:blue;
			}
			.done p
			{
				color:red;
			}
		</style>
		
		<script >
			function change_class_name() {
				var els = document.getElementsByClassName('halo');
				els[0].parentElement.parentElement.className = 'done';
			}
		</script>
	</head>

	<body onload="javascript:change_class_name()">
		<table>
			<tr>
				<td class="test">
					<div>
						<div class="halo">
							<p>Hello World</p>
						</div>
					</div>
				</td>
				<td class="test">
					<div>
						<div class="hai">
							<p>Hello World</p>
						</div>
					</div>
				</td>
			</tr>
		</table>
	</body>

</html>

When you should call the function change_class_name() is up to you.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900