The following hides images that have Stud_Btn
in their id.
$('img[id^="Stud_Btn"]').hide();
even if I have Stud_Btn1234
and Stud_Btn234
, it will still hide it. What does "^" really mean?
Can it not only be used for parison? Or does it have other uses?
The following hides images that have Stud_Btn
in their id.
$('img[id^="Stud_Btn"]').hide();
even if I have Stud_Btn1234
and Stud_Btn234
, it will still hide it. What does "^" really mean?
Can it not only be used for parison? Or does it have other uses?
Share Improve this question edited Apr 1, 2019 at 19:52 Archmede 1,8423 gold badges24 silver badges41 bronze badges asked Mar 17, 2013 at 12:47 Jomar SevillejoJomar Sevillejo 1,6982 gold badges21 silver badges33 bronze badges 9- 3 api.jquery./attribute-starts-with-selector – ScottE Commented Mar 17, 2013 at 12:49
- 1 All available selectors: api.jquery./category/selectors – Alejandro Urbano Alvarez Commented Mar 17, 2013 at 12:49
- 1 What Chevi said. Did you not try Googling jQuery selectors? – ClarkeyBoy Commented Mar 17, 2013 at 12:51
- 1 @user2128576 Try SymbolHound for searching for special characters! – ComFreek Commented Mar 17, 2013 at 14:06
- 1 @user2128576: Google "jQuery selectors" - 4th link down is the official jQuery documentation. No need to search for the symbols. Scroll down on that page and find Selectors > Attributes. Click this and ^= is the 7th one down. – ClarkeyBoy Commented Mar 17, 2013 at 15:00
5 Answers
Reset to default 8It's an attribute starts-with selector. Your specific example will match any img
element whose id
attribute starts with the string "Stud_Btn".
The jQuery API documentation is the best place to go for simple questions like this. I would strongly remend spending a bit of time reading through it.
[attr^=val]
a CSS selector that means:
Element that has an attribute named
attr
with a value that starts withval
.
It's similar to [attr$=val]
, which does the opposite, looking for an attribute ending with val
.
It gets all the images that have their Ids starting with Stud_btn
It means "attribute starts with", see documentation.
It means "startes with". Continue reading here.