Project new objects from jQuery selector -


Is there a way to project an object with jQuery selection? As a simplified example, suppose I want an array of objects that correspond to the anchor of my page; In each object, TNT refers to anchor text, and the value is related to that data-id etter.

  var results = []; $ ("A") (Function (i, o) {result.push ({txt: $ (o) .text (), val: $ (o) .data ("id")}}}); DoSomething (result);   

It is possible to do something like C # selection:

  doSomething ($ ("a"). Select (function (i, o) {( {ID} "post-text" itemprop = "text"> 

You can use the method to project a set:

  doSomething ($ ("a") Map (function (o, i) {note: that << {  

code> index and element parameter in unknown callback Do not ask why :-) If you do not keep an eye on the index that you can leave them and do this:

  doSomething ($ ("a"). Map (function () {return {txt: $ (this) .text (), Val: $ (this) .data ("id")}}});    

Comments

Popular posts from this blog

mysql - BLOB/TEXT column 'value' used in key specification without a key length -

c# - Using Vici cool Storage with monodroid -

python - referencing a variable in another function? -