I want to know how to find the class along with number digits, for instance, the class maybe like this: .test_ico1, .test_ico2, .test_ico3, .test_ico4.
Jquery
$('.test_ico' + '/[0-9]/').each(function(){
var a = window.getComputedStyle(this,':after').content;
$(this).parent().hover(function(){
$(this).attr('data-content', a);
});
});
You can use ^(starts with) symbol.
Also it's called Attribute Starts With Selector
$('[class^="test_ico"]').each(function(){
Short example:
$('[class^="myClass"]').each(function(){
$(this).addClass('active');
});
.active{
color:red;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<ul>
<li class="myClass1">1</li>
<li class="myClass2">2</li>
<li class="Class3">3</li>
</ul>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With