I'm facing an issue with the .find method when using a name=value selector. Despite having the correct syntax and knowing that the object I am selecting from contains 7 elements with the desired attribute, the .find is unable to locate any elements. This has left me puzzled as to why it's not working as expected.
Here is the JavaScript code on the page:
$(document).ready(function () {
var mainCatName = 'category.SelectedValue'
$('#Button1').on('click', function () {
var td = $('input[name="' + mainCatName + '"]:checked').parent('td');
var tdIndex = td.index();
if (selectElems == null) {
//1
selectElems = $("#pumpConfigTable td:nth-child(" + (tdIndex + 1) + ") select, #pumpConfigTable td:nth-child(" + (tdIndex + 1) + ") input");
}
var projectInfoID = $('#ProjectInfoID').attr('value');
var mainCategoryID = $('input[name="' + mainCatName + '"]:checked').attr('value');
var postBackObject = makeProjectInfoObjects(projectInfoID, mainCategoryID, selectElems);
var blah = "blah";
});
});
Here is a snippet of the makeProjectInfoObjects function:
function makeProjectInfoObjects(pInfoID, mainCatID, pcOptions) {
var pc = new Array();
var dbIDs = _.pluck(pcOptions, "data-dbid");
var uniquedbIDs = _.unique(dbIDs);
uniquedbIDs = _.reject(uniquedbIDs, function (checkID) { return checkID == undefined; });
var len = uniquedbIDs.length;
for (var i = 0; i < len; ++i) {
var categories = $(pcOptions).find("[data-dbid='" + uniquedbIDs[i] + "']");
var uniqueNames = _.pluck(categories, "name");
var singleOptions = $(categories).find(':not([name]');
var soLen = singleOptions.length;
for (var j = 0; j < soLen; ++j) {
pc.push({
pcID: uniquedbIDs[i],
pInfoID: pInfoID,
configCatID: mainCatID,
configSubCatID: $(singleOptions[i]).attr('data-subcatid'),
configValue: $(singleOptions[i]).attr('value')
});
I am currently using JQuery 1.8.1 and IE8 on XP.
Upon inspecting with IE Developer Tools, I found that the first selector works perfectly fine: //1
"#pumpConfigTable td:nth-child(2) select, #pumpConfigTable td:nth-child(2) input"
However, the second selector seems to be causing the trouble: //2
"#pumpConfigTable td:nth-child(2) select, #pumpConfigTable td:nth-child(2) input [data-dbid='1']"