TeTe TeTe - 4 months ago 28
jQuery Question

find elements which id contains two substrings

I have an HTML table and I need to change the CSS style to all de

contains the substring
and the substring
using jquery. The substrings could be in any position of the string.

I use this, but it doen't work:



You can use square brackets to select by attribute:


And in case of this question it's even better to narrow it down to only td elements:


"[id*='str']" means "find an element where attribute 'id' contains string 'str' anywhere".

More info at jQuery documentation: http://api.jquery.com/attribute-contains-selector/

EDIT: This selector is available in css, not only in jQuery, so if '_A_189' and '_B_V_852' parts are static, you should consider adding it to your stylesheet instead of using scripts. For instance:

table td[id*='_A_189'][id*='_B_V_852'] {
    /* your styles */