Can array members act as multiple jQuery selectors, AND as individually matched objects?

It's a common circumstance, but after a through Google + SO search, I have been unable to find a simple solution.. Although similar to this question, the point is not to amass a multi-dimensional array, but simply to ACT on whichever selector "Won", not on the entire "sum" of selectors. Example:

var findThese = ['name', 'telephone', 'brasize']; var chiXML = "<philly><name>sandy</name><brasize>49DDD</brasize></philly>" + "<philly><name>amber</name><telephone>976</telephone></philly>"; $(findThese).find(chiXML) .parent() .data(the_1of3_matched_selector_from_findThese, theMatched Text);

ending up with something vaguely like...

<philly data-name="sandy" data-brasize="49DDD"> <name>sandy</name><brasize>49DDD</brasize></philly> </philly>....

Sorry if my example sucks... but what I'm getting at... is it possible to "transliterate" a list / array - as a "multiple choice" jQuery selector - which can then be acted with OR upon INDIVIDUALLY, during the callback / function portion of the query operation?

-------------Problems Reply------------

I think you want something like this:

$.each(findThese, function(i, selector) {
.each(function () {
$(this).parent().data(selector, $(this).text());

If I understand you correctly, you need to know what part of a multiple selector your results match and act on that value.

You can break up the selector as I've done above and act on each piece independently, making it easier for you to know what part of the selector was satisfied.

Category:jquery Views:0 Time:2011-08-24

Related post

  • an array of strings as a jQuery selector? 2009-06-16

    I have an array of strings that are valid jQuery selectors (i.e. IDs of elements on the page): ["#p1", "#p2", "#p3", "#p4", "#p5"] I want to select elements with those IDs into a jQuery array. This is probably elementary, but I can't find anything on

  • How do I store multiple jQuery selectors in a javascript variable? 2011-01-27

    Obviously it's a good idea to store jQuery selectors in variables if they are used more than once (not a good idea if used only once). My question is, how do you store multiple selectors, that are used interchangeably, in a variable. For instance, le

  • jQuery selectors select from an HTML object other than from document root? 2010-06-09

    jQuery selectors select from the document. How do I select from somewhere else other than root? Say I want to select some children from an HTML object. For this function dothis(obj) { $j("#tabs").removeClass(); $j("#tabs>ul").removeClass(); $j("#t

  • multiple JQuery selectors in a queue 2011-07-18

    I am trying to discover if it is possible to use the .queue() method in JQuery with multiple selectors in the same queue. I can't find any examples of where things are added to the same queue from different selectors. for example: $('#aDiv').queue(fu

  • Multiple jquery Selectors 2011-03-12

    Thanks to karim79 i am able to click on the ImageButton and apply the Jquery highlight effect to a different div $("#btnFavorite").click(function() { // selector for element to highlight $("#theDiv").effect("highlight", {}, 3000); }); Now i would lik

  • Using multiple jQuery selectors to filter 2010-08-19

    I am trying to add the jQueryUI datepicker on a certain group of datefields, but exclude fields whose id ends in -0 Here is my code: $(function() { $("input[id^='TOEFLtestDate-']").not([id$='-0']).datepicker({ onClose: function(dateText, inst){ Gener

  • jQuery selector needed for first matched element 2010-11-23

    I have the following code: <p class="expand">Click to expand</p> <div class="expand-box"> <p>Some content here</p> </div> with this jquery: $('.expander-box').hide(); $('.expand').toggle(function() { $(this).next('

  • jQuery: .each how to reference matched object 2010-02-24

    how do i get a reference to the element that matched? 'this' is not correct. For example here I am trying to alert with the elements value. //how do i get this to reference the object it matches. $("#txtFirstName,#txtLastName,#txtDOB").each( function

  • jQuery selector for uncommon tag ID 2011-07-15

    I have this tag ID, pretty uncommon: <select name="/State" id="/State"> It seems I cannot use jQuery selector $('#/State') to select this object. I can select it using $("#\U002FState"), but I cannot print the id attribute: javascript:alert($("

  • How does jQuery act on multiple selectors? 2011-04-30

    I've been wondering for a little while how jQuery acts on multiple selectors. For instance: $("p").css({"border":"1px solid #000"}); Performs the subsequent function on all p tags. I've had a look through the jQuery source but to be honest it's an ex

  • How to write a jQuery selector with multiple :eq's in single expression? 2011-12-09

    I have a quick question. How do I write a jQuery selector expression with multiple :eq() selectors? I want to go down the DOM tree but every hope isn't uniform. Here is what I have that works: $('div:eq(0)').find('div:eq(1)').find('div:eq(5)') But is

  • how do you pass an array index to a jquery selector? 2012-03-15

    How would you use an array index as a jquery selector? for example if I have: array[0] = someId; array[1] = someId; for(var i; i<array.length; i++){ $("#"+array[i]").find(.....) } I would like to be able to use the value stored in the array index

  • Multiple Parameters for jQuery selector? 2010-04-20

    I was just looking at the jQueryUI button plug-in and noticed this $("button, input:submit, a", ".demo").button(); I never seen something like this. Is this like multiple selects in one jQuery selector? --------------Solutions------------- The second

  • Multiple web forms vs jquery selectors 2010-08-24

    I'm reading Steven Sanderson's book Pro ASP.NET MVC 2 Framework. In his book, he use multiple web forms on a single web page to list products from database and provide Add to cart functionality. When should I take this approach vs having single web f

  • Storing jquery selector arrays? 2011-07-26

    Below you can see that I store the results of the jquery selector in an array. I then use this array to perform other functions. This example here doesn't seem to work, it's behaving as if the var/array is a live selector, not the results when they w

  • JQuery selector form element php array 2011-10-12

    im trying to use the code below to select a form element (i retrieve the values to validate the text) $('#box1 [name=item[]]').val(); $('#box2 [name=item[]]').val(); i'm trying to get the value of the following <form..> <div id='box1'>

  • How to pass multiple jquery arrays to controller in MVC 2010-02-17

    I have tried to get an example but was noy successful so far. I have created various arrays and filled them in jquery. How to post all of them to the controller? On the controller side how to retrieve them and their values? I would appreciate if I ca

  • jquery selector for multiple classes 2011-06-08

    I have elements in my DOM with class="LiveVal:variablepart" and i would like to write a JQuery selector that works even if the elements have other classes on tom of the above. Eg. class="header LiveVal:varablepart" or class="LiveVal:varablepart heade

  • jquery selector inside a table with multiple div's 2011-06-23

    i am trying to reach a value in my code which is in a loop through jquery selector but i cannot figure it out because i am still a noob in jquery selector: <tr > <td class="qtip" title="asjdasd"> <?php foreach ($this->titles as $tit

Copyright (C), All Rights Reserved.

processed in 0.145 (s). 11 q(s)