0

Element ID :

<div class="text_title_9a9f19a9 text_title-191 textListLayoutTitle_9a9f19a9">

I am want to get this element using below code

$("div:regex(class, .text_title_\*.text_title-\*.textListLayoutTitle_\*)");

but it's not working

In element id "9a9f19a9" and "191" and "9a9f19a9" are dynamically change the value so that's why I am using * instead of that

Sebastian Kaczmarek
  • 8,120
  • 4
  • 20
  • 38
Chandresh
  • 121
  • 7

2 Answers2

1

You can use the selector div[class^=text_title] to select all div that has a class starting with text_title, this way you don't have to use a regex for it.

$("div[class^=text_title]")

If you wish to look for multiple classes on the div you can do it like this:

$("div[class*=text_title_][class*=text_title-][class*=textListLayoutTitle_]")

Demo

console.log($("div[class*=text_title_][class*=text_title-][class*=textListLayoutTitle_]").length)
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<div class="text_title_9a9f19a9 text_title-191 textListLayoutTitle_9a9f19a9"></div>

<div class="text_title_9a9f19a9 textListLayoutTitle_9a9f19a9"></div>
Carsten Løvbo Andersen
  • 26,637
  • 10
  • 47
  • 77
0

You can make use of filter() function and use indexOf to check containing classess

$(function(){
  $('div').filter(function(){
    var classes = $(this).attr('class');
    if(classes.indexOf('text_title_') != -1 && classes.indexOf('text_title-') != -1 && classes.indexOf('textListLayoutTitle_') != -1) {
      return true;
    } else {
      return false;
    }
  }).addClass('valid');
});
.valid {
  color: green;
}

div {
  color: blue;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.0/jquery.min.js"></script>
<div class="text_title_9a9f19a9 text_title-191 textListLayoutTitle_9a9f19a9">Valid</div>
<div class="text_title-191 textListLayoutTitle_9a9f19a9">InValid</div>
<div class="text_title_9a9f19a9 textListLayoutTitle_9a9f19a9">InValid</div>
Bhushan Kawadkar
  • 28,279
  • 5
  • 35
  • 57