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(unic)'<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

  • 's with the id's returned by intersection ??

  • 有帮助吗?

    解决方案

    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/

    许可以下: CC-BY-SA归因
    不隶属于 StackOverflow
    scroll top