Note that there are some explanatory texts on larger screens.

plurals
  1. POLooking for specific class when clicked
    primarykey
    data
    text
    <p>I have two div containers:</p> <pre><code>&lt;!-- button1 --&gt; &lt;div class="voted"&gt; &lt;span&gt;name&lt;/span&gt; &lt;div class="button"&gt;Vote&lt;/div&gt; &lt;/div&gt; &lt;!-- button2 --&gt; &lt;div class="vote"&gt; &lt;span&gt;name&lt;/span&gt; &lt;div class="button"&gt;Vote&lt;/div&gt; &lt;/div&gt; </code></pre> <p>Then when using jquery:</p> <pre><code>$('.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" }); </code></pre> <p>I would like to use something like <code>$(this)</code> 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 <code>button1</code>, I would like them to get class of <code>button2</code>, vice versa.</p> <p><strong>EDIT</strong></p> <p>So I have two buttons (to compare two people), initially, they're supposed to have the same class <code>vote</code>. But I have jQuery codes that when a user clicks on a button, the class changes to <code>voted</code>. 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 <code>voted</code> class, or they already pressed the first button.</p> <p>I know that I can just check my whole page if <code>voted</code> 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 <code>vote</code>).</p> <p>My whole premise is: not to allow user vote the other person if user already voted for someone.</p> <p>Sorry for the long description.</p> <p>Thanks!</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload