JavaScript JQuery: toggle Q&A class with plus and minus icons jquery toggle class onclick,jquery toggle class animation,jquery toggleclass

I am trying to toggle plus and minus span and also toggle the answer div all at once and its not working out. I built the html so the question div has two childrens:

  1. div icons with two children of plus and minus icons
  2. div for the answer

this is the code:

$( document ).ready(function() {
  $(".question").click(function(){
    $(this).children(".icons div").toggle();
	  $(this).next('.answer').slideToggle();			    	
	});
});
.question div{
  display: table-cell;
  font-size: 17px;
  font-weight: bold;
  color:blue;
  cursor: pointer;
}
.question .icons .MinusIcon{
  display: none;
}
.answer{
  display:none;
  padding-left: 5%;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>

<!---------------1--------------->
		<div class="question">
			<div class="icons">
				<div class="plusIcon">[<span>+</span>]</div>
				<div class="MinusIcon">[<span>-</span>]</div>
			</div>
			<div>
				Question<br>Question
			</div>
		</div>
		<div class="answer">
			ANSWER<br> ANSWER<br> ANSWER<br> ANSWER
		</div>
		<!---------------2--------------->
		<div class="question">
			<div class="icons">
				<div class="plusIcon">[<span>+</span>]</div>
				<div class="MinusIcon">[<span>-</span>]</div>
			</div>
			<div>
				Question<br>Question
			</div>
		</div>
		<div class="answer">
			ANSWER<br> ANSWER<br> ANSWER<br> ANSWER
		</div>
Answer:1

Try this :

  $( document ).ready(function() {
            $(".question").click(function(){            

                $(this).find(".plusIcon").toggle();
                $(this).find(".MinusIcon").toggle();    
                $(this).next('.answer').slideToggle();
            });

        });
Answer:2

Change Your Function

$(this).find(".icons div.plusIcon").toggle();
$(this).find(".icons div.MinusIcon").toggle();

$( document ).ready(function() {
		    $(".question").click(function(){
		    	$(this).find(".icons div.plusIcon").toggle();
$(this).find(".icons div.MinusIcon").toggle();
		    	$(this).next('.answer').slideToggle();			    	
		    });
 
	 	});
.question div{
  display: table-cell;
  font-size: 17px;
  font-weight: bold;
  color:blue;
  cursor: pointer;
}
.question .icons .MinusIcon{
  display: none;
}
.answer{
  display:none;
  padding-left: 5%;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>

<!---------------1--------------->
		<div class="question">
			<div class="icons">
				<div class="plusIcon">[<span>+</span>]</div>
				<div class="MinusIcon">[<span>-</span>]</div>
			</div>
			<div>
				Question<br>Question
			</div>
		</div>
		<div class="answer">
			ANSWER<br> ANSWER<br> ANSWER<br> ANSWER
		</div>
		<!---------------2--------------->
		<div class="question">
			<div class="icons">
				<div class="plusIcon">[<span>+</span>]</div>
				<div class="MinusIcon">[<span>-</span>]</div>
			</div>
			<div>
				Question<br>Question
			</div>
		</div>
		<div class="answer">
			ANSWER<br> ANSWER<br> ANSWER<br> ANSWER
		</div>
Answer:3

With little modifications in OP's code, here's how it looks:

  $(".question").on('click', function() {
    var $answer = $(this).next('.answer');
    var visible = $answer.is(':visible');
    $(this).children('.icons').text(visible ? '[+]' : '[-]');
    $answer.slideToggle();
  });
.question div {
  display: table-cell;
  font-size: 17px;
  font-weight: bold;
  color: blue;
  cursor: pointer;
}
.answer {
  display: none;
  padding-left: 5%;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class="question">
  <div class="icons">[+]</div>
  <div>
    Question
  </div>
</div>
<div class="answer">
  ANSWER
  <br>ANSWER
  <br>ANSWER
  <br>ANSWER
</div>
<div class="question">
  <div class="icons">[+]</div>
  <div>
    Question
  </div>
</div>
<div class="answer">
  ANSWER
  <br>ANSWER
  <br>ANSWER
  <br>ANSWER
</div>
Answer:4

I am a beginner with typescript and playing with it on their Playground site. I have the following code: class Queue<T> { private data = []; push = (item: T) => this.data.push(item)...

I am a beginner with typescript and playing with it on their Playground site. I have the following code: class Queue<T> { private data = []; push = (item: T) => this.data.push(item)...

  1. typescript doesn't compile
  2. typescript doesn't compile on save
  3. typescript doesn't work
  4. typescript doesn't understand
  5. typescript does not like
  6. typescript import doesn't work
  7. typescript instanceof doesn't work
  8. typescript exclude doesn't work
  9. typescript concat doesn't work
  10. typescript await doesn't work
  11. typescript filter doesn't work
  12. typescript await doesn't wait
  13. typescript foreach doesn't work
  14. typescript getter doesn't work
  15. typescript regex doesn't work
  16. typescript settimeout doesn't work
  17. typescript object doesn't support this action
  18. typescript includes does not work
  19. typescript typings doesn't work
  20. typescript property does not exists

I've been struggling with sending a POST request and fetching data back using Node.js I've been trialing like this var querystring = require('querystring'); var http = require('http'); var postData ...

I've been struggling with sending a POST request and fetching data back using Node.js I've been trialing like this var querystring = require('querystring'); var http = require('http'); var postData ...

  1. send post request javascript
  2. send post request python
  3. send post request curl
  4. send post request from chrome
  5. send post request online
  6. send post request java
  7. send post request postman
  8. send post request c#
  9. send post request powershell
  10. send post request php
  11. send post request from command line
  12. send post request golang
  13. send post request react
  14. send post request js
  15. send post request from terminal
  16. send post request html
  17. send post request in url
  18. send post request node
  19. send post request with parameters
  20. send post request to localhost

I am attempting to use the canActivate feature on my app routing, however whenever I compile the app the log shows constantly refreshing with fail messages that I had console.log()'d out for ...

I am attempting to use the canActivate feature on my app routing, however whenever I compile the app the log shows constantly refreshing with fail messages that I had console.log()'d out for ...

I have site which contains many links. User can open links in new window. User can log out from one window. If they do so and click on the other window of my site then I want to give an alert to the ...

I have site which contains many links. User can open links in new window. User can log out from one window. If they do so and click on the other window of my site then I want to give an alert to the ...