how to find the id of an array of elements and placing them into a var using jquery?
I have a file called text.txt that contains:
<li id="unic1">some text</li>
<li id="unic2">some text</li>
and a index.html where I try to find the id from the previous file:
<div id="div">alert(u开发者_如何学运维nic)'<div>
$(".div").load('text.txt');
$source.each(function(){
var $unic = $("li").attr('id');
});
what am I doing wrong?
thanks edit: thanks for response.
i found that i can gram the id's like this:
var unic = $('div.hidde').find('li').map(function(i, v) { return this.id; }).get();
var unic1 = $('div.hi').find('li').map(function(i, v) { return this.id; }).get();
and i can combine them using this script:
var intersection = [];
$(liList).each(function () {
for (i in unic) {
for (j in unic1) {
if (unic[i] == unic1[j]) intersection.push(unic[i]);
}
}
});
alert(intersection);
another questions is how to remove the
You should use the complete callback for the load function:
$('#result').load('text.txt', function() {
//When load is complete
$('.div ul').each(function(){
var $unic = $("li").attr('id');
});
});
More details on callbacks for the load method here: http://api.jquery.com/load/
精彩评论