The Universal Selector * is slow, (not much in CSS but) when used in JS. So probably you can use some right selectors, classes or something (cannot say without any HTML sample or in-depth description).
But your code can be refactored to:
- Extract the number out of your class
- Map Numbers to
h, v, b characters
const num2Frame = {1:"h", 2:"v", 3:"v", 4:"b"}; // map class num to frame char
jQuery(function ($) { // DOM ready and $ alias secured
$("[class^='wrap-around'], [class*=' wrap-around']").each(function() {
// extract number from className
const num = (this.className.match(/wrap-around(\d+)/)||'')[1];
if (!num) return;
$(this).find("*") //instead of * use a specific selector
.wrapAll(`<div class="frame-${num2Frame[num]}" />`)
.addClass('outer'+ num);
});
});
.outer1{color: green;}
.outer2{color: gold;}
.outer3{color: gold;}
.outer4{color: red;}
.frame-h{ border: 1px solid green; }
.frame-v{ border: 1px solid gold; }
.frame-b{ border: 1px solid red; }
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class="asd wrap-around1 qwe sdfg"><p>1</p></div>
<div class="asd wrap-around2 qwe sdfg"><p>2</p></div>
A total improvement would be refactoring your selectors and HTML and use the right tools for the job:
const num2Frame = {1:"h", 2:"v", 3:"v", 4:"b"}; // map class num to frame char
jQuery(function ($) { // DOM ready and $ alias secured
$("[data-wrap]").each(function() {
const num = $(this).data("wrap");
$(this).children()
.wrapAll(`<div class="frame-${num2Frame[num]}" />`)
.addClass('outer'+ num);
});
});
.outer1{color: green;}
.outer2{color: gold;}
.outer3{color: gold;}
.outer4{color: red;}
.frame-h{ border: 1px solid green; }
.frame-v{ border: 1px solid gold; }
.frame-b{ border: 1px solid red; }
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div data-wrap="1"><p>1</p></div>
<div data-wrap="2"><p>2</p></div>
*is slooooooooow, really slow selector. Are you sure*is really needed? Without seeing your HTML any answer here is just guesswork.