I am trying to get all text boxes that have an id that ends in a particular string.
So far I have tried
$("input[id$='Source']").each(function() {
$("input[type=text][id$='Source']").each(function() {
and also
$("input[type=text] , [id$='Source']").each(function() {
none of these seem to work, could some one maybe point me in the right direction.
I have tried clearing my web browsers cache just to make sure it was not caching any old code.
I am trying to get all text boxes that have an id that ends in a particular string.
So far I have tried
$("input[id$='Source']").each(function() {
$("input[type=text][id$='Source']").each(function() {
and also
$("input[type=text] , [id$='Source']").each(function() {
none of these seem to work, could some one maybe point me in the right direction.
I have tried clearing my web browsers cache just to make sure it was not caching any old code.
Share Improve this question edited Apr 11, 2014 at 19:45 scunliffe 63.7k26 gold badges131 silver badges166 bronze badges asked Apr 11, 2014 at 19:24 mpopmpop 4991 gold badge12 silver badges21 bronze badges 4- 4 Post some of the HTML -> also check the console, any errors? – tymeJV Commented Apr 11, 2014 at 19:26
-
1
Your use of quotes is a bit inconsistent. Without testing it this should work:
$("input[type='text'][id$='Source']")
– Kevin Boucher Commented Apr 11, 2014 at 19:27 - @tymeJV I will post some of the HTML later, I will have to clean out some stuff that I can not post first, and to your second question, I have watched the javascript console and I don't see any errors in there. the only message in there is ":visited and :link styles can only differ by color. Some styles were not applied to :visited." and I doubt that that would have any effect on the code i am looking at. – mpop Commented Apr 11, 2014 at 19:34
- 2 The first two selectors you posted both works. This indicates the problem lies somewhere else. Perhaps a missing semicolon or something along that path. – agrm Commented Apr 11, 2014 at 19:36
2 Answers
Reset to default 3This works:
<input type="text" id="mysource">
<input type="text" id="yoursource">
<input type="text" id="nope">
js (the context 'this' inside of the each function will be the matched elements):
$("input[type='text'][id$='source']").each(function() {
console.log(this);
});
console result:
<input type="text" id="mysource">
<input type="text" id="yoursource">
Clean up your quotes and you should be OK -
$('input[id$="Source"]').each(function() {
$('input[type="text"][id$="Source"]').each(function() {
Here is an example fiddle - http://jsfiddle/C5v4H/