Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to find string with number selector in jquery

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);
    });
});
like image 735
jinfy Avatar asked Dec 02 '25 21:12

jinfy


1 Answers

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>
like image 52
Mihai Alexandru-Ionut Avatar answered Dec 05 '25 10:12

Mihai Alexandru-Ionut



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!