0

I am trying to have my button (id="AnswersEx1") when it is clicked, to toggle on/off the (class="FrenchStage1Ex1") text. There are at least two instances of that class being used.

My html:

<h5>
  <button class="AnswerTitle" id="AnswersEx1">Reveal Answers</button>
</h5>
<li>
  <p>
    the passeport
    <textarea></textarea>
    <span class="FrenchStage1Ex1">
      la passeport
    </span>
  </p>
</li>
<li>
  <p>the briefcase
    <textarea></textarea>
    <span class="FrenchStage1Ex1">
      la valise
    </span>
  </p>

Disclaimer: I did spend more than 2 days searching everything similar. This is unique because it has a class (not a div), a person who understands 0 javascript, and the class is attached to span tags in different <p></p> groups (which may affect how it is hidden)

Aelfric
  • 11
  • 3
  • 1
    It took 10 seconds to find a duplicate on "button show hide javascript" - the duplicate is using a div, but any html object will work with the answers given. Your HTML is invalid by the way – mplungjan Aug 06 '17 at 16:19
  • You need an `onClick` function on the button tag, or you can add it in Javascript with `addEventListener`. Then, you can remove/add the class inside the function/listener. – aashah7 Aug 06 '17 at 16:20
  • this is not a duplicate. i have seen everything similar. i don't know the javascript and the divs are very different. i have various text inside

    .groups. the button must somehow make the text between the spans dissapear. i couldn't find a way to make display none and display block to work. there must be an appropriate answer
    – Aelfric Aug 06 '17 at 16:26
  • can you please revise your duplicate tag because people won't give this a chance – Aelfric Aug 06 '17 at 16:30
  • https://jsfiddle.net/mplungjan/a7Lfjsgh/ – mplungjan Aug 06 '17 at 16:36
  • If you do not know JavaScript then this question was off topic. Please visit the [help] to see what and how to ask. The idea is to post effort and code in a [mcve] - I have taken your HTML and created a custom example for you alone. The duplicate I posted has ALL the examples needed to do what you need assuming you know some JavaScript. – mplungjan Aug 06 '17 at 16:40
  • I don't know what you are talking about. I have improved the post only slightly just now. I have my html. People can see i have a button. and the two places that i want to affected. you are using political correct speak in a very bad way. Your example of hiding a div is not the same with spans. – Aelfric Aug 06 '17 at 16:45
  • Please understand that SO is not an elancing site. Not only is your question off topic if you do not understand enough JavaScript to use the duplicate posted, but I went the extra step and wrote you a personalised script you can use - I posted the example in a comment 10 minutes age - here it is again https://jsfiddle.net/mplungjan/a7Lfjsgh/ – mplungjan Aug 06 '17 at 16:47
  • If I had not closed it, it would have been voted down and closed ANYWAY - _Questions seeking debugging help ("why isn't this code working?") must include the desired behavior, a specific problem or error and the shortest code necessary to reproduce it in the question itself. Questions without a clear problem statement are not useful to other readers_ – mplungjan Aug 06 '17 at 16:48

0 Answers0