Link to home
Start Free TrialLog in
Avatar of kumar naik
kumar naikFlag for India

asked on

if table is dispalyed border should display if it is hidden border should be remove.

how to write if else condition  if table is displayed  border "class" should add . and if table is not displayed border  ''"class" should remove.
 This is Sample Code only. 
when i am hidding the table border is displayed i want to hide the border when table is hidden. 
<!DOCTYPE html>
<html>
<head>
	<title></title>
	<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
	<style type="text/css">
		.border{
			border:1px solid red;
		}
	</style>

	<script type="text/javascript">
		$(document).ready(function(){
			if ($(table) == display:none) {
				$(table).removeClass("border")
			}
		})
	</script>



</head>
<body>

	<div class="border">
		<table>
			<thead>
				<th>2121321</th>
				<th>2121321</th>
				<th>2121321</th>
				<th>2121321</th>
				<th>2121321</th>
				<th>2121321</th>
				<th>2121321</th>

			</thead>
			<tbody>
				<tr>
				<td>2121321</td>
				<td>2121321</td>
				<td>2121321</td>
				<td>2121321</td>
				<td>2121321</td>
				<td>2121321</td>
				<td>2121321</td>
				</tr>
				<tr>
				<td>2121321</td>
				<td>2121321</td>
				<td>2121321</td>
				<td>2121321</td>
				<td>2121321</td>
				<td>2121321</td>
				<td>2121321</td>
				</tr>
				<tr>
				<td>2121321</td>
				<td>2121321</td>
				<td>2121321</td>
				<td>2121321</td>
				<td>2121321</td>
				<td>2121321</td>
				<td>2121321</td>
				</tr>
				<tr>
				<td>2121321</td>
				<td>2121321</td>
				<td>2121321</td>
				<td>2121321</td>
				<td>2121321</td>
				<td>2121321</td>
				<td>2121321</td>
				</tr>

				
			</tbody>
		</table>
	</div>

</body>
</html>

Open in new window

Avatar of Julian Hansen
Julian Hansen
Flag of South Africa image

<script>
$(function(){
	if ($('.border table:visible').length == 0) {
		$('.border').removeClass("border")
	}
})
</script>

Open in new window

Another version
<script>
$(function(){
	$('table:hidden').each(function(i, e) {
		$(e).closest('.border').removeClass('border');
	})
})
</script>

Open in new window

Avatar of kumar naik

ASKER

how to remove if it is an ID border   not class border
how to write if the table is in the display:none position. not in hidden
ASKER CERTIFIED SOLUTION
Avatar of Julian Hansen
Julian Hansen
Flag of South Africa image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
sorry forgot to close solution was very helpful thanku
You are welcome.