I have two div containers:
<!-- button1 -->
<div class="voted">
<span>name</span>
<div class="button">Vote</div>
</div>
<!-- button2 -->
<div class="vote">
<span>name</span>
<div class="button">Vote</div>
</div>
Then when using jquery:
$('.button').click(function(){
// if button2 was clicked:
var test = $(this).parent().attr("class"); // How do I obtain the other element?
alert(test); // this should be outputted "voted"
});
I would like to use something like $(this) with some function to get the other element. How would I obtain “voted”? The reason I’m doing this is because I have a script where it will change between two buttons, so when user clicks on button1, I would like them to get class of button2, vice versa.
EDIT
So I have two buttons (to compare two people), initially, they’re supposed to have the same class vote. But I have jQuery codes that when a user clicks on a button, the class changes to voted. Now, I would like to check so that when a user clicks on the OTHER button (to try to vote for the second person), they can’t because there’s already a voted class, or they already pressed the first button.
I know that I can just check my whole page if voted exists, but I have set up some check when user clicks on their initial voted person that they voted for, they can take back the vote (which will change the div class back to vote).
My whole premise is: not to allow user vote the other person if user already voted for someone.
Sorry for the long description.
Thanks!
I solved what I’m trying to do
This allows me to check if class voted exists, but it doesn’t check if $(this) one that was pressed exists.