JavaScript Hide/Show Divs with Javascript and sort by value? hide show divs,hide show divs jquery,show hide divs

I have these two scripts, one sorts divs by a value in a div class (price) and the other shows or hides divs based on class name with buttons. (box a, box b etc, inside a "parent" class.)

The problem is they do not work together, you can show a class but not sort the results by price, the price sorting only works on all the divs at once, and breaks after, you need to reload.

fiddle:

https://jsfiddle.net/qjwL1pqa/4

Is there any way to have a single script that does both? lets you show hide divs based on a class, and sort the results by price (ascending / descending) and vice verse?

I hope this makes sense.

Script for showing / hiding Divs based on class name:

var $boxs = $("#parent > .box");
var $btns = $(".btn").on("click", function() {

var active = 
$btns.removeClass("active")
  .filter(this)
  .addClass("active")
  .data("filter");

$boxs
.hide()
.filter( "." + active )
.fadeIn(450);

});

Script for sorting Divs based on class value:

$('#byPrice').on('click', function () {
 $('#parent div.price').map(function () {
  return {val: parseFloat($(this).text(), 10), el: this.parentNode};
 }).sort(function (a, b) {
  return a.val - b.val;
 }).map(function () {
  return this.el;
 }).appendTo('#parent');
});
$('#byPrice1').on('click', function () {
 $('#parent div.price').map(function () {
   return {val: parseFloat($(this).text(), 10), el: this.parentNode};
 }).sort(function (a, b) {
   return b.val - a.val;
 }).map(function () {
   return this.el;
 }).appendTo('#parent');
});

Example Product Div:

 <div id="parent">

    <div class="box a">
        <div class="product_box">   
            <div class="price">19.99</div>
            </div>
    </div>

 <div/>
Answer:1

For some reason I have to do this for(let i=0;i<=6;i++){ price.push({ min_price: `this.state.special_${i}_min`, max_price: `this.state.special_${i}_max` }); } But it's not ...

For some reason I have to do this for(let i=0;i<=6;i++){ price.push({ min_price: `this.state.special_${i}_min`, max_price: `this.state.special_${i}_max` }); } But it's not ...

I have an array that creates a conversation between two people where it 'flips' between the browser speaking and the browser listening. Short version, how do I make saySomething queue for(var i=0; ...

I have an array that creates a conversation between two people where it 'flips' between the browser speaking and the browser listening. Short version, how do I make saySomething queue for(var i=0; ...

  1. queue javascript events

I have a Node.js route that sends back some text and logs the request: app.post('/registerUser', function (req, res) { res.send('Hello World post!') console.log(req); }) Then I hit that route ...

I have a Node.js route that sends back some text and logs the request: app.post('/registerUser', function (req, res) { res.send('Hello World post!') console.log(req); }) Then I hit that route ...

  1. node inspect websockets request was expected
  2. inspect request node.js

I have this array: [{ name: "A1", arr: [1,2] }, { name: "A2", arr: [1] }] How do I can split the first one object to two objects that should contains only one array value? The result should be: [...

I have this array: [{ name: "A1", arr: [1,2] }, { name: "A2", arr: [1] }] How do I can split the first one object to two objects that should contains only one array value? The result should be: [...

  1. split array objects
  2. split array objects javascript
  3. split objects array js
  4. split array into objects
  5. split array of objects php
  6. split array of objects lodash
  7. split array of json objects
  8. split array of json objects python
  9. javascript split array of objects by property
  10. logstash split array of objects
  11. split json array into objects
  12. javascript split array into objects
  13. powershell split array of objects
  14. typescript split array of objects by property
  15. java split array of objects
  16. typescript split array of objects