TeTe TeTe - 1 year ago 158
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:


Answer Source

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 */
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download