---
title: "jQuery hide() hides what it shouldn't"  
description: "jQuery hide() hides what it shouldn't"  
author: "Anonymous User"  
published: 2015-01-28  
updated: 2015-01-28  
canonical: https://www.mindstick.com/forum/12913/jquery-hide-hides-what-it-shouldn-t  
category: "asp.net"  
tags: ["jquery", "javascript"]  
reading_time: 2 minutes  

---

# jQuery hide() hides what it shouldn't

I've got problem... jQuery should only hide divs under each h2, but it hides those h2 aswell... What should I do?

<![DOCTYPE](https://www.mindstick.com/interview/23388/what-is-the-importance-of-the-html-doctype)>

<html>

<head>

<[title](https://www.mindstick.com/articles/12860/how-to-get-financing-for-salvage-title-cars)>Yolo</title>

<[script](https://www.mindstick.com/interview/477/how-can-i-execute-a-php-script-using-command-line) src="js/jquery-1.11.2.min.js"></script>

</head>

<body>

<main>

<div [class](https://www.mindstick.com/blog/165/generic-class-in-c-sharp)="faq">

<h2>Opcja 1</h2>

<div class="answer">

<p>Paragraph under [option](https://www.mindstick.com/forum/159391/jquery-get-selected-option-from-dropdown) 1!</p>

</div>

<h2>Opcja 2</h2>

<div class="answer">

<p>Paragraph under option 2!</p>

</div>

<h2>Opcja 3</h2>

<div class="answer">

<p>Paragraph under option 3!</p>

</div>

</div>

</main>

<script src="js/jquery-1.11.2.min.js"></script>

<script src="js/szkrypt.js"></script>

</body>

</html>

And there is jQuery. I did this via course in book, there it worked, maybe there was something with css classes there... Or maybe it was that, it was done under older [version of jQuery](https://www.mindstick.com/interview/2538/which-command-will-give-a-version-of-jquery).

$([document](https://www.mindstick.com/articles/328642/what-to-consider-while-choosing-a-software-documentation-tool)).ready([function](https://www.mindstick.com/articles/13001/multi-statement-table-valued-user-defined-function-in-sql-server)() {

$('.answer').hide();

$('.faq h2').toggle(

function() {

$(this).next('.answer').slideDown();

},

function() {

$(this).next('.answer').fadeOut();

}

);

});

## Replies

### Reply by Anonymous User

The toggle function you're trying to use is **deprecated and removed** !

The only toggle() function that is left in jQuery, is the one that toggles visibility, and that's why it's hiding everything.

$('.faq h2').toggle();

... hides every visible h2 element, and shows every hidden h2 element

You'll have to create your own toggle

```
$('.answer').hide();$('.faq h2').on('click', function() {    var flag = $(this).data('flag');     if ( !flag ) {       $(this).next('.answer').slideDown();    } else {      $(this).next('.answer').fadeOut();    }     $(this).data('flag', !flag);});
```

Also, remove the script tag that is loading jQuery in the head, once is enough !


---

Original Source: https://www.mindstick.com/forum/12913/jquery-hide-hides-what-it-shouldn-t

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
