Page 1 of 1

.click only working on one button? [jquery]

Posted: Fri Jun 11, 2010 8:38 pm
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>

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

Posted: Fri Jun 11, 2010 9:04 pm
by Eran
the id attribute is unique. You can't have two elements with the same id in the page. Use a class instead

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

Posted: Sun Jun 13, 2010 11:12 am
by Cirdan
Ah didn't think about that. Thanks