Why Do I Get Only One Element Array By $('a') With Jquery Instead Of All Of Them?
Solution 1:
This should do the work
var link = $("a").map(function() {
returnthis.innerHTML;
}).get();
console.log(link.join());
Put in function what you want to retrieve from html.
Solution 2:
Assuming you are using google chrome here. This seems like an issue where stuff typed in google chrome console window is executing in the context of the parent (or root) page.
Change the context.
See how this is done in jsfiddle.
Changing the context:
Now you can do whatever you want:
Solution 3:
everyone:
I found the problem that the forum has. I debug in the jquery.js and found after
push.apply( results,
newContext.querySelectorAll( newSelector )
(it is at line 864, https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.js)
results
just push one element in it, and then I found another js from the forum called common.js
define the function push
, like this:
Array.prototype.push = function(value) {
this[this.length] = value;
returnthis.length;
}
So the function push
does the wrong thing.
This question may be not a good question, because this situation is too special. But I learn how to debug from the js code and DO NOT override native function arbitrarily.
Finally, thanks for everyone who helped me.
Post a Comment for "Why Do I Get Only One Element Array By $('a') With Jquery Instead Of All Of Them?"