0

I want to target all the button which has a buttonid starts from tab_btn(number)

Is there a way to select element in css this way. I cannot make use of jquery as CSS is only the restriction.

<input id="FormControl_V1_I1_S1_I1_B1" scriptclass="Button" class="dh_LmyGLHecqegKZ42V_0 dj_LmyGLHecqegKZ42V_0" formid="FormControl" originalid="V1_I1_S1_I1_B1" tabindex="0" title="" buttonid="tab_btn1" value="General" type="button">

<input id="FormControl_V1_52_J1_I1_B1" scriptclass="Button" class="dh_LmyGLHecqegKZ42V_0 dj_LmyGLHecqegKZ42V_0" formid="FormControl" originalid="V1_I1_S1_I1_B1" tabindex="0" title="" buttonid="tab_btn2" value="General" type="button">

Class and other attribute wont be constant here, But the ID will have a series starting tab_btn1, tab_btn2 etc

2
  • Why you tagged jQuery ? Commented Nov 9, 2016 at 6:49
  • Jquery users might have an answer to this. Commented Nov 9, 2016 at 7:02

3 Answers 3

2

Just do [id^="tab_btn"] as a selector. It will target all IDs beginning with tab_btn

See the docs https://api.jquery.com/attribute-contains-selector/

Sign up to request clarification or add additional context in comments.

4 Comments

[id^=tab_btn] should be [id^="tab_btn"].
There is no need to use the quotes
If it were being used as a selector from JavaScript the quotes would be nessecery, but yea css has no such requirement
It isn't needed in javascript either, at least not jQuery
1

Check this example:

Set a background color on all elements that have a class attribute value that begins with "test":

div[class^="test"] {
    background: #ffff00;
} 

Comments

0

Attribute selector in css. The [attribute^="value"] selector is used to select elements whose attribute value begins with a specified value.

input[buttonid^= "tab_btn"] {
  background: yellow;
}
<input id="FormControl_V1_I1_S1_I1_B1" scriptclass="Button" class="dh_LmyGLHecqegKZ42V_0 dj_LmyGLHecqegKZ42V_0" formid="FormControl" originalid="V1_I1_S1_I1_B1" tabindex="0" title="" buttonid="tab_btn1" value="General" type="button">

<input id="FormControl_V1_52_J1_I1_B1" scriptclass="Button" class="dh_LmyGLHecqegKZ42V_0 dj_LmyGLHecqegKZ42V_0" formid="FormControl" originalid="V1_I1_S1_I1_B1" tabindex="0" title="" buttonid="tab_btn2" value="General" type="button">

<input id="FormControl_V1_H2_M1_I1_B1" scriptclass="Button" class="dh_LmyGLHecqegKZ42V_0 dj_LmyGLHecqegKZ42V_0" formid="FormControl" originalid="V1_J1_T1_I1_B1" tabindex="0" title="" buttonid="tab2" value="General" type="button">

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.