Juri
Juri

Reputation: 331

Traversing the DOM with load() method

In jQuery, the .load() method allows you to import the specific content, for example, of a certain id using selectors:

$("#div1").load("demo_test.txt #p1");

With jQuery (and if possible without functions but just using selectors), how do I select, for example, the previous element to that id?

Eg 1 (mistaken):

$("#div1").load("demo_test.txt #p1").prev();

Eg 2 (mistaken):

$("#div1").load("demo_test.txt #p1.prev()"); 

Upvotes: 1

Views: 41

Answers (1)

Pranav C Balan
Pranav C Balan

Reputation: 115262

You can't do that with load() method instead of that use jQuery.get and get the element from the response.

$.get("demo_test.txt",function(res){ 
  $("#div1").html($(res).find('#p').prev()); 
},'html') 

Upvotes: 1

Related Questions