JavaScript Differentiate between group of buttons differentiate between group and team,differentiate between group discussion and

Is it possible to differentiate between a group of buttons? Given the following buttons.

<div id="slideout_inner">
<h2>Select Size</h2>
<p id="group1">
<button type="button" class="btn btn-primary btn-lg">Small $2.50</button>
<button type="button" class="btn btn-default btn-lg">Medium $3.50</button>
<button type="button" class="btn btn-default btn-lg">Large $4.50</button> 
</p>
<h2>Select Milk</h2>
<p>
<button type="button" class="btn btn-default btn-lg">Full</button>
<button type="button" class="btn btn-default btn-lg">Trim</button>
<button type="button" class="btn btn-default btn-lg">Soy</button>
</p>

<button type="button" class="btn btn-primary btn-lg btn-block">Done</button>
<button type="button" class="btn btn-danger btn-lg btn-block       cancelOrder">Cancel</button>
</div>
</div> 

If I do the following I can highlight the selected button in group1

    $('#group1 button').on("click", function(){
    $('#group1 button').removeClass("btn-primary").addClass("btn-default");
    $(this).removeClass("btn-default").addClass('btn-primary');
    })

I expect the button list to be dynamic so I want to select buttons with <p> to highlight separately so remove the #group selector and just highlight buttons within each <p>.

So in this example I could highlight Medium $3.50 and then highlight Soy independently.

Answer:1

Try this code:

  $(document).ready(function () {

    $("button").on("click", function () {
        $(this).siblings("button").removeClass("btn-primary").addClass("btn-default");
        $(this).removeClass("btn-default").addClass('btn-primary');
    });

});
Answer:2

Try selecting only children of the parent <p> instead of all #group1 buttons.

$(this).parent().find("button").removeClass("btn-primary").addClass("btn-default");

This way you are only accessing a subset of buttons within the parent element, instead of running the query on the entire DOM.

Answer:3

You can use .siblings to select all sibling elements so you can find all sibling elements of the clicked .btn element:

$("p .btn").on("click", function() {
    $(this).siblings(".btn").removeClass("btn-primary").addClass("btn-default");
    $(this).removeClass("btn-default").addClass('btn-primary');
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div id="slideout_inner">
<h2>Select Size</h2>
<p id="group1">
<button type="button" class="btn btn-primary btn-lg">Small $2.50</button>
<button type="button" class="btn btn-default btn-lg">Medium $3.50</button>
<button type="button" class="btn btn-default btn-lg">Large $4.50</button> 
</p>
<h2>Select Milk</h2>
<p>
<button type="button" class="btn btn-default btn-lg">Full</button>
<button type="button" class="btn btn-default btn-lg">Trim</button>
<button type="button" class="btn btn-default btn-lg">Soy</button>
</p>

<button type="button" class="btn btn-primary btn-lg btn-block">Done</button>
<button type="button" class="btn btn-danger btn-lg btn-block       cancelOrder">Cancel</button>
</div>
</div> 
Answer:4

function openNav() { document.getElementById("mySidenav").style.width = "200px"; } /* Set the width of the side navigation to 0 */ function closeNav() { document.getElementById("mySidenav")....

function openNav() { document.getElementById("mySidenav").style.width = "200px"; } /* Set the width of the side navigation to 0 */ function closeNav() { document.getElementById("mySidenav")....

So I've set the session according to the documentation for express-session, as far as I can tell. But my cookie is not getting created! According to the documentation, all you have to do is set the ...

So I've set the session according to the documentation for express-session, as far as I can tell. But my cookie is not getting created! According to the documentation, all you have to do is set the ...

  1. express session working
  2. express session not working
  3. express-session doesn't work
  4. express session maxage not working
  5. express session destroy not working
  6. express session rolling not working
  7. express session redis not working
  8. express session cookie maxage not working
  9. iis express session not working
  10. express cookie session not working
  11. express session secure cookie not working
  12. express-mysql-session not working
  13. express js session not working
  14. passport express-session not working
  15. express-session not work

I am adding a class .error on click and now after time interval of 2 seconds I want to remove this class, but without page reload/refresh.I used delay() in jQuery as: $('#username').addClass('error')....

I am adding a class .error on click and now after time interval of 2 seconds I want to remove this class, but without page reload/refresh.I used delay() in jQuery as: $('#username').addClass('error')....

  1. if hasclass then remove class jquery
  2. add class then remove class jquery
  3. add class then remove class
  4. jquery fadeout then remove class
  5. jquery delay then remove class
  6. if has class then remove class
  7. remove class then addclass jquery
  8. jquery addclass delay then remove class
  9. jquery if hasclass then remove class
  10. jquery if hasclass then add class

I am trying make a responsive page with three div(each div is a column), where one column is sometimes hidden.What I aim to implement is: 1.When three divs are shown, width should be 100%. When one ...

I am trying make a responsive page with three div(each div is a column), where one column is sometimes hidden.What I aim to implement is: 1.When three divs are shown, width should be 100%. When one ...

  1. auto adjust width excel
  2. auto adjust width css
  3. auto adjust width in html
  4. auto adjust width of columns in excel
  5. auto adjust width excel shortcut
  6. auto adjust width of cells in excel
  7. auto adjust width
  8. auto adjust width vba