Link to home
Start Free TrialLog in
Avatar of Vipin Kumar
Vipin KumarFlag for India

asked on

jQuery code not working as expected

Hi,

I have used a jQuery code show below from source and modified it so that when  the advanced search button in the content of the first tab is clicked it would show the table containing id adv-search and when that button is clicked again it would again hide the table containing id adv-search. But the script is not working as expected, i.e. when the advanced search button is clicked it shows the table and immediately hides it back without clicking the button again. which I don't want to happen. I want to hide the content to hide only when the advanced search button is clicked again.

Kindly let me know any inputs required. I am attaching the most of the code.

Can someone help me with identifying what is the issue?

Thanks in advance.
<div class="tabs">
					<ul class="tab-links">
						<li class="active" style="margin-left: 150px;"><a href="#tab1">PO's</a></li>
						<li><a href="#tab2" style="margin-left: 175px;">Device's</a></li>
					</ul>
					<hr>
					<div class="tab-content">
						<form id="tab1" class="tab active">
							<h2>List of PO's</h2>
							<input type="text">&nbsp;&nbsp;&nbsp;<button>Search</button>&nbsp;&nbsp;&nbsp;<button id="advsearch-btn">Advanced Search</button>
							<table id="adv-search">
								<td>123</td>
								<td>234</td>
								<td>234</td>
								<tr><td>asd</td></tr>
							</table>
						</form>
						<form id="tab2" class="tab">
							<p>Tab #2 content goes here!</p>
							<p>Test Conten.</p>
						</form>
					</div>
				</div>

Open in new window

$(document).ready(function() {
	$('.tabs .tab-links a').on('click', function(e)  {
		var currentAttrValue = $(this).attr('href');
		$('.tabs ' + currentAttrValue).slideDown(400).siblings().slideUp(400);// Show/Hide Tabs
		$(this).parent('li').addClass('active').siblings().removeClass('active');// Change/remove current tab to active
		e.preventDefault();
	});
	$('#adv-search').hide();//added this code myself
	$('#advsearch-btn').click(function(){//added this code myself
		$('#adv-search').toggle();//added this code myself
	});//added this code myself
});

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of leakim971
leakim971
Flag of Guadeloupe 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
another way :
$('#advsearch-btn').click(function(){//added this code myself
            $('#adv-search').toggle();//added this code myself
            return false;
      });//added this code myself