I can not understand how to make the ID of the elements loaded on the page, the Ajax-Ohm was transmitted to the processing. On jQuery I can not assemble the array of these elements.
In the Internet, I found the most interesting:
var arr = array ($ ('UL Li'). Attr ('id'));
The outlet array should look: 1,2,3,56,81.5
Such a line is needed to make a SQL request on the server with
where id in ('. $ arr.')
I tried: & lt; li name = "arr ['. $ Row [' id '].']" & GT;
But jQuery displays only the first element and with square brackets:
alert ($ ('UL Li'). attr ('name');
Answer 1, Authority 100%
Cycles are not needed here.
HTML
& lt; ul id = "list" & gt;
& lt; li id = "1" & gt; list 1 & lt; / li & gt;
& lt; li id = "2" & gt; list 2 & lt; / li & gt;
& lt; li id = "3" & gt; list 3 & lt; / li & gt;
& lt; / ul & gt;
jQuery
var arrlist = $ ('# List Li'). Map (function () {
Return $ (this) .attr ('id');
}). Get ();
Alert (arrlist);
Answer 2, Authority 67%
var arr = new array ();
var i = 0;
$ ('Li'). Each (Function () {
arr [i] = $ (this) .attr ('id');
I ++;
});
and so if …
Answer 3, Authority 33%
You can still try on Pure-JS
+ jQuery:
HTML:
& lt; ul & gt;
& lt; li id = "p1" & gt; 1 & lt; / li & gt;
& lt; li id = "p2" & gt; 2 & lt; / li & gt;
& lt; li id = "p3" & gt; 3 & lt; / li & gt;
& lt; li id = "p4" & gt; 4 & lt; / li & gt;
& lt; li id = "p5" & gt; 5 & lt; / li & gt;
& lt; / ul & gt;
JS:
& lt; script & gt;
var newarr = new array (); // Array ID TVNes
arr = $ ('ul & gt; li'); // Another array of DOM objects
for (i = 0; i & lt; arr.length; i ++)
newarr.push ($ (arR [i]). ATTR ("ID"));
alert (newarr.length); // "5"
& lt; / script & gt;