.click only working on one button? [jquery]

JavaScript and client side scripting.

Moderator: General Moderators

Post Reply
Cirdan
Forum Contributor
Posts: 144
Joined: Sat Nov 01, 2008 3:20 pm

.click only working on one button? [jquery]

Post by Cirdan »

I have two divs that act as a container(like a tab control). At the bottom, I have a span button setup so when I click the X, it hides that dive. This works with the first #trialineate button, but does absolutely nothing for the second #redeemed button. Why is .click only working for one button?

Code: Select all

		$("#hidetab").click(function() {
		
			tab = $(this).find('a').attr("href");
			alert(tab);
			$(tab).slideUp('fast');
			
			
			return false;
		});
		
	});
...

Code: Select all

			<div id="trialineate" class="tab_content">
				...
				<span style="text-align: right; width: 100%;display:block;" id="hidetab"><a href="#trialineate">x</a></span>
			</div>
			<div id="redeemed" class="tab_content">
				...
				<span style="text-align: right; width: 100%;display:block;" id="hidetab"><a href="#redeemed">x</a></span>
			</div>
Last edited by pickle on Mon Jun 14, 2010 10:17 am, edited 1 time in total.
Reason: Updated code tags
User avatar
Eran
DevNet Master
Posts: 3549
Joined: Fri Jan 18, 2008 12:36 am
Location: Israel, ME

Re: .click only working on one button? [jquery]

Post by Eran »

the id attribute is unique. You can't have two elements with the same id in the page. Use a class instead
Cirdan
Forum Contributor
Posts: 144
Joined: Sat Nov 01, 2008 3:20 pm

Re: .click only working on one button? [jquery]

Post by Cirdan »

Ah didn't think about that. Thanks
Post Reply