JavaScript Group and show items of same type

I have a listView of items and these items are to be grouped together based on a class and shown with boxes.

Suppose I have 5 items with:

<div class="1"></div>
<div class="1"></div>
<div class="2"></div>
<div class="3"></div>
<div class="3"></div>

enter image description here

Need boxes just like this to show the similar items.

Once we add a new item to the ViewModel with a class of 1, the box needs to add the new item to the first box.

Can anyone help me out in how to group the items which have same class and how do we show a box with CSS on the items which have same class?

Answer:1

You can use a bit of jQuery to wrap all elements with matching class names with a wrapper:

var elems = $('div').map(function() {
    return $(this).attr('class');
});
$.unique(elems).each(function(i, el) {
    $('.'+el).wrapAll('<div class="wrapper"></div>');
});

You can then just apply your CSS to the .wrapper class (or name it whatever you want).

Here is a Codepen example.

Answer:2

Trying to figure out the cleanest way to do the following: I'm filtering some results twice, and I'm using Lodash filter to do so. Currently, my code looks like: resultsOne = _.filter(results, ...

Trying to figure out the cleanest way to do the following: I'm filtering some results twice, and I'm using Lodash filter to do so. Currently, my code looks like: resultsOne = _.filter(results, ...

  1. lodash filter with multiple conditions
  2. lodash filter with index
  3. lodash filter with or condition
  4. lodash filter with multiple values
  5. lodash filter with array
  6. lodash filter with regex
  7. lodash filter with keys
  8. lodash filter with map
  9. lodash filter with includes
  10. lodash filter with function
  11. lodash filter with or
  12. lodash filter with limit
  13. lodash filter with object
  14. lodash filter with sort
  15. lodash filter with chain
  16. lodash filter with predicate
  17. lodash filter by value
  18. lodash filter by property
  19. lodash filter by date
  20. lodash filter by multiple properties

I have a problem hiding xAxes and yAxes labels on small screen sizes (mobile phones). I know there is this option: options: { scales: { xAxes: [{ ...

I have a problem hiding xAxes and yAxes labels on small screen sizes (mobile phones). I know there is this option: options: { scales: { xAxes: [{ ...

  1. chartjs hide labels on x axis
  2. chartjs hide labels
  3. chart js hide labels pie
  4. chart js hide labels doughnut
  5. chartjs hide label dataset
  6. chartjs hide label in tooltip
  7. chartjs hide label legend
  8. chartjs hide label color
  9. chartjs hide label x
  10. chartjs hide label line
  11. chartjs hidden label
  12. chartjs hide axis labels
  13. chartjs hide xaxis labels
  14. chartjs hide some labels
  15. chartjs radar hide labels
  16. chartjs hide data labels
  17. chartjs hide tick labels
  18. chartjs pie hide labels
  19. react chartjs hide labels
  20. chartjs hide y axis labels

I encountered a challenge when trying to activate autoload on scrolling to the bottom. The problem is that the jQuery doesn't work when I scroll to the bottom but when I scroll back to the top, it ...

I encountered a challenge when trying to activate autoload on scrolling to the bottom. The problem is that the jQuery doesn't work when I scroll to the bottom but when I scroll back to the top, it ...

  1. windows scroll not working
  2. windows scroll doesn't work
  3. scroll doesn't work windows
  4. windows scroll wheel not working
  5. windows scroll bar not working
  6. windows scroll pad not working
  7. windows scroll feature not working
  8. windows touchpad scroll not working
  9. windows 10 scroll not working
  10. windows mouse scroll not working
  11. windows 10 scroll not working touchpad
  12. windows trackpad scroll not working
  13. windows 7 scroll not working
  14. windows 10 scroll stopped working
  15. windows update scroll not working
  16. windows 8 scroll not working
  17. windows 10 scroll not working in settings
  18. windows horizontal scroll not working
  19. windows scroll inactive window not working
  20. windows page scroll not working

i am pretty new to javascript and doing a course to gain some experience but i am breaking my head on the return concept sometimes. Basically this is the task i am stuck at: There is an array of ...

i am pretty new to javascript and doing a course to gain some experience but i am breaking my head on the return concept sometimes. Basically this is the task i am stuck at: There is an array of ...