-1

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 comparison? Or does it have other uses?

Archmede
  • 1,592
  • 2
  • 20
  • 37
Jomar Sevillejo
  • 1,648
  • 2
  • 21
  • 33
  • 3
    http://api.jquery.com/attribute-starts-with-selector/ – ScottE Mar 17 '13 at 12:49
  • 1
    All available selectors: http://api.jquery.com/category/selectors/ – aurbano Mar 17 '13 at 12:49
  • 1
    What Chevi said. Did you not try Googling jQuery selectors? – ClarkeyBoy Mar 17 '13 at 12:51
  • Even [searching SO for `[jquery] "^="`](http://stackoverflow.com/search?q=%5Bjquery%5D+%22%5E%3D%22) would have revealed some use cases. – Felix Kling Mar 17 '13 at 12:53
  • @ClarkeyBoy and FelixKling Google sucks at small searches.. Read my Edit.. thanks for replying though.. I appreciate the time you've given.. – Jomar Sevillejo Mar 17 '13 at 14:05
  • 1
    @user2128576 Try [SymbolHound](http://www.symbolhound.com/) for searching for special characters! – ComFreek Mar 17 '13 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 Mar 17 '13 at 15:00
  • @ClarkeyBoy Thanks! this is Really useful too. I will pin this to my browser so I won't have to search it again. thanks! – Jomar Sevillejo Mar 18 '13 at 13:00
  • Possible duplicate of [jQuery or CSS selector to select all IDs that start with some string](http://stackoverflow.com/questions/5002966/jquery-or-css-selector-to-select-all-ids-that-start-with-some-string) – Jomar Sevillejo Nov 24 '15 at 09:04

5 Answers5

7

It'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 recommend spending a bit of time reading through it.

James Allardice
  • 164,175
  • 21
  • 332
  • 312
  • Thank you for taking the time to reply sir :) Though you are right, but I don't have the time to do so read all of what's in the documentation. I am a student working on a project :) Thanks for replying though, my experience here in stackoverflow.com has been great thanks to people like you :)) – Jomar Sevillejo Mar 17 '13 at 13:58
5

[attr^=val] a CSS selector that means:

Element that has an attribute named attr with a value that starts with val.

It's similar to [attr$=val], which does the opposite, looking for an attribute ending with val.

Niet the Dark Absol
  • 320,036
  • 81
  • 464
  • 592
2

It gets all the images that have their Ids starting with Stud_btn

dlock
  • 9,447
  • 9
  • 47
  • 67
2

It means "attribute starts with", see documentation.

matt
  • 359
  • 1
  • 7
2

It means "startes with". Continue reading here.

Langusten Gustel
  • 10,917
  • 9
  • 46
  • 59