Why are the two options of my toggle () executing?

Lleims

I have made a button with a link, <a>, and I want to use it to display or not some elements. For this objective I thought .toggle() was a good option.

$('#filter_btn').click(function() {
  $('.filters_container').toggle(function() {
    $(".filters_container").css({
      display: "flex"
    });
  }, function() {
    $(".filters_container").css({
      display: "none"
    });
  });
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<a href="#" id="filter_btn">Nodes</a>

But with this code, when I press the button it shows filters_container but immediately they become invisible again. Why is executing both parts of the toggle function?

Thank very much.

Krishna Jonnalagadda

$(function(){
$('#filter_btn').click(function() {
   $("p").toggle();
});
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<div>
<a href="#" id="filter_btn">Nodes</a>
<p style="display:none">testing</p>
</div>

이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.

침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제

에서 수정
0

몇 마디 만하겠습니다

0리뷰
로그인참여 후 검토

관련 기사

Android Studio: my sms app is not one of the options for default SMS app

Why are git-stash options not prefixed with dashes?

Why does one of my two Dell monitors unexpectedly enter power save mode when using DisplayPort daisychaining?

JQuery toggle() stuck with two diffrent button click

Why do I have two desktop.ini files on my windows 8 desktop?

why is mockito not called when executing mocked method?

Why is my TextBox not binding?

Perl "\my $var" why is the "my" escaped with a backslash?

Why are my variables not reset to zero?

Why is my GPU overheating?

Why is Terminal automatically executing my command after pasting text?

Toggle between two different vim configurations?

Why does my "Quiz" program keep making two options correct answers?

Function with toggle options

Why my 2nd while loop in not executing?

Why has my Mac been running fsck_hfs for two days now?

Why is my clearfix not working?

Why is my request body empty?

Why is my div not horizontally centered?

Why does my nixos installation have two paths to 'nixpkgs'?

Regex conditional: give the user exactly two options

Why are .show() and .hide() toggling even though I'm not using toggle?

How do I see what output options are available in my proc?

One menu item to toggle between two states in WatchKit Context Menu

Unexpected output when comparing my input string to certain options

Why some GitHub actions stopped executing?

Toggle a boolean with two buttons

Why my font color in navbar didn't change when i toggle to sticky?

Toggle Two Divs Onclick JavaScript

TOP 리스트

뜨겁다태그

보관