Ok i spend a lot of time on finding how to work this around using JQuery, but i finally found a solution.
Say we have some elements in our page that we don’t know their ID’s. For example in my case I was printing dynamically select elements but did not know their ID cause each id had an integer to distinguish it from the others. What i wanted to do was to reset all select boxes with a certain word in their ID’s to their first element as soon as one of them changed.
For example all the elements that i wanted to change had the word “upgrade” in them plus some other numbers. What I did was on the onChange function that would trigger the event:
$("select[id^=upgrade]").each(function() {
$(this).val("-");
});
which would return to me all elements that started with the word upgrade. JQuery selectors are great. Using the each function you can go around all selectors and set the value of each select box to “-” which in my case the “-” was the first element of each select box. Usually you will have as the first element something like “0″ or “” (empty).
Also searching I found this interesting snippet which didnt work for me, but i assume i did something wrong.
$('#myElement').html();
You can use \\S* to make wildcard selections, I.E.:
$('#myEle\\S*').each();
Dont know why it didnt work on my case….
Related posts:
- Custom info windows with jQuery and Google Maps Ben Nolan has a writeup on a new feature in...







February 3rd, 2009 at 7:17 pm
ropox
Wow! Thank you so much for this information. Your [id^=blah] works like a charm.
I also want to point out, I had a very similar problem to solve. I also went around the Net to search for a wild card selector.
\\S* – doesn’t work for me either.
February 3rd, 2009 at 9:04 pm
well i’m glad I helped someone on this task, cause really I was banging my head to figure out what I was doing wrong : )
At least i know the \\S* wildcard is not working on someone else either..
February 11th, 2009 at 11:52 pm
Another “me too” for \\S* not working..
I’m semi curious to know what it is that we’ve all missed, but it’s hard to justify spending much time on it when the method you’ve posted above works fine
February 27th, 2009 at 2:04 pm
ropox: Thanks for this tip. I was starting to get crazy with all the variations of ‘\\S*’ I tried and none worked.
July 22nd, 2009 at 3:21 pm
There is a lot you can do to select the required items you want to manipulate.
Have a look at the docs to view all possibilities: http://docs.jquery.com/Selectors
In my case I needed the: input[name$='letter'] to select the required items because I use JSF to generate the pages.
October 21st, 2009 at 2:24 am
Excellent post, thanks so much for the info, it helped a lot!!
February 5th, 2010 at 4:19 pm
Try the id$=upgrade instead. $= seems to be the wildcard selector.