Selector Context not working as advertised.
On this page
http://api.jquery.com/jQuery/#jQuery-selector-context the instructions for using the selector context says:
By default, selectors perform their searches within the DOM starting at the document root. However, an alternate context can be given for the search by using the optional second parameter to the $() function. For example, to do a search within an event handler, the search can be restricted like so:
$( "div.foo" ).click(function() {
$( "span", this ).addClass( "bar" );
});
When the search for the span selector is restricted to the context of this, only spans within the clicked element will get the additional class.
So I have a div called "pnNsnDialog" + lineID (which in this case is 4 so "pnNsNDialog4")
In side of it are two divs one called "NSNsHolder" + lineID ( or NSNsHolder4)
and the other called "PNsHolder" + lineID (PNsHolder4)
Each of these divs have input controls located within.
I only want the ones from "PNsHolder" + lineID
so I used a selector like this
- var selector = "input[id *= 'rb_'], #PNsHolder" + lineID;
$(selector).each(function () {
debugger
alert($(this).attr('id'));
- //some other stuff
- });
However instead of only getting the inputs whose ids contain "rb_" and which reside in "#PNsHolder4", I am getting every element within "pnNsNDialog4" including both divs, and all of the inputs in each div whether they contain "rb_" or not. This is odd because earlier on the page I m using
- $("td[id*='tdPNDoDIC']").click(function (e) {});
which only sets the click event on td's with an id containing "tdPNDoDIC" and
- $(".prLine_PRLine_DoDIC", "#tdPNDoDIC" + lineID).val(dodic.toUpperCase());
which only sets the value of the element with the class prLine_PRLine_DoDIC in the <td> "#tdPNDoDIC" + lineID .
I don't see what I am doing incorrectly here.