Trying to get panels to disappear with the click of a button

John M.

I'm working myself through this tutorial but I'm using jQuery and Bootstrap instead of what I think the author used, which was jQuery mobile? In any event I cannot get it to work. https://www.youtube.com/watch?v=Cc3K2jDdKTo&list=UUVTlvUkGslCV_h-nSAId8Sw&index=97

When the user clicks Btn1 I want panel1 to disappear. Clicking Btn2 causes panel2 to disappear and so on. Could someone help me out on where I'm going wrong? Thank you.

HTML

<div class="container">
  <!-- Provides extra visual weight and identifies the primary action in a set of buttons -->
<button type="button" class="btn btn-primary" myPanel="panel1">Btn 1</button>

<!-- Secondary, outline button -->
<button type="button" class="btn btn-secondary" myPanel="panel2">Btn 2</button>

<!-- Indicates a successful or positive action -->
<button type="button" class="btn btn-success" myPanel="panel3">Btn 3</button>

<!-- Contextual button for informational alert messages -->
<button type="button" class="btn btn-info" myPanel="panel4">Btn 4</button>

</div>

<div class="container">
    <div class="row">
        <div class="col-xs-3" id="panel1">
            first panel
        </div>
        <div class="col-xs-3" id="panel2">
            second panel
        </div>
        <div class="col-xs-3" id="panel3">
            third panel
        </div>
        <div class="col-xs-3" id="panel4">
            fourth panel
        </div>
    </div> <!--/.row-->
</div> <!--/.container-->

JS

$(document).ready(function(){
    $(".btn").click(function(){
        var panelID = $(this).attr('myPanel');
        $('#' + panelId).toggle();
    });
});
Parvez Rahaman

You have variable name mistake var panelID you used as panelId.

$(".btn").click(function(){
    var panelID = $(this).attr('myPanel');
    $('#' + panelID).toggle();
});

$(document).ready(function(){
    $(".btn").click(function(){
        var panelID = $(this).attr('myPanel');
        $('#' + panelID).toggle();
    });
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class="container">
  <!-- Provides extra visual weight and identifies the primary action in a set of buttons -->
<button type="button" class="btn btn-primary" myPanel="panel1">Btn 1</button>

<!-- Secondary, outline button -->
<button type="button" class="btn btn-secondary" myPanel="panel2">Btn 2</button>

<!-- Indicates a successful or positive action -->
<button type="button" class="btn btn-success" myPanel="panel3">Btn 3</button>

<!-- Contextual button for informational alert messages -->
<button type="button" class="btn btn-info" myPanel="panel4">Btn 4</button>

</div>

<div class="container">
    <div class="row">
        <div class="col-xs-3" id="panel1">
            first panel
        </div>
        <div class="col-xs-3" id="panel2">
            second panel
        </div>
        <div class="col-xs-3" id="panel3">
            third panel
        </div>
        <div class="col-xs-3" id="panel4">
            fourth panel
        </div>
    </div> <!--/.row-->
</div> <!--/.container-->

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Trying to get panels to disappear with the click of a button

From Dev

Change panels with one button of a click

From Dev

jQgrid after Click on Reload Grid button, all data get disappear

From Dev

trying to get a timestamp inputed upon a click of the button

From Dev

How to Create New Panels on Button Click?

From Dev

Add panels inside a panel dynamically on button click

From Dev

How to Create New Panels on Button Click?

From Dev

HTML <input> button(s) disappear on click

From Java

Bootstrap's tooltip doesn't disappear after button click & mouseleave

From Dev

Why does the value is displayed and then disappear after I click on the button in JavaScript?

From Dev

How can I make a div disappear and reappear on button click?

From Dev

click home button in fragment page to disappear action bar activity title

From Dev

Amchart Export button and menu do not disappear after click

From Dev

Espresso AmbiguousViewMatcherException when trying to click a navigation button

From Dev

Trying to display div on radio button click

From Dev

Trying to create imageView when click the button

From Dev

Panels disappear from Box when event is triggered

From Dev

Trying to get this SVG to cover the button?

From Java

Get button click inside UITableViewCell

From Dev

Get Array element on button click

From Dev

Tkinter Button Will Not Get Focus on Click

From Dev

Get Array element on button click

From Dev

JavaScript get recognize button to click

From Dev

How to get notification on Button Click?

From Dev

Get a Javascript variable on the click of button

From Dev

get addition without button click

From Dev

Click Tab, Tabs Disappear

From Dev

JavaScript, Trying to get buttons to move on click

From Dev

Trying to get click function to work on website

Related Related

  1. 1

    Trying to get panels to disappear with the click of a button

  2. 2

    Change panels with one button of a click

  3. 3

    jQgrid after Click on Reload Grid button, all data get disappear

  4. 4

    trying to get a timestamp inputed upon a click of the button

  5. 5

    How to Create New Panels on Button Click?

  6. 6

    Add panels inside a panel dynamically on button click

  7. 7

    How to Create New Panels on Button Click?

  8. 8

    HTML <input> button(s) disappear on click

  9. 9

    Bootstrap's tooltip doesn't disappear after button click & mouseleave

  10. 10

    Why does the value is displayed and then disappear after I click on the button in JavaScript?

  11. 11

    How can I make a div disappear and reappear on button click?

  12. 12

    click home button in fragment page to disappear action bar activity title

  13. 13

    Amchart Export button and menu do not disappear after click

  14. 14

    Espresso AmbiguousViewMatcherException when trying to click a navigation button

  15. 15

    Trying to display div on radio button click

  16. 16

    Trying to create imageView when click the button

  17. 17

    Panels disappear from Box when event is triggered

  18. 18

    Trying to get this SVG to cover the button?

  19. 19

    Get button click inside UITableViewCell

  20. 20

    Get Array element on button click

  21. 21

    Tkinter Button Will Not Get Focus on Click

  22. 22

    Get Array element on button click

  23. 23

    JavaScript get recognize button to click

  24. 24

    How to get notification on Button Click?

  25. 25

    Get a Javascript variable on the click of button

  26. 26

    get addition without button click

  27. 27

    Click Tab, Tabs Disappear

  28. 28

    JavaScript, Trying to get buttons to move on click

  29. 29

    Trying to get click function to work on website

HotTag

Archive