I am somewhat new to jquery and have no idea if this is possible, so here goes.
Basically, I am using an ajax get request, the result is in valid html, I already can select a specific object on the page that I want, and I want to then use that to get all of its siblings, this is how the code looks:
$.ajax(
{
type: 'GET',
url: requestUrl,
dataType: 'html',
success: function(data, textStatus)
{
var allLinks = $(data).find("a");
allLinks.each(function(){
if($(this).text() == 'selectme'){
$(this).parent().children("a").last().css('color', 'red');
}
});
}
});
This is what the response looks like:
<html>
<body>
<a>irrelevant link 1</a>
<div>
<a>selectme</a>
<a>sibling 1</a>
<a>sibling 2</a>
<a>last sibling, which I want to get</a>
</div>
<a>irrelevant link 2</a>
<a>irrelevant link 3</a>
</body>
</html>
So, basically, I want to get the last sibling of the selectme link. Is it possible to make parent use the response instead of the actual page elements, and if not, how can I get the siblings without getting any of the irrelevant links? I could use the index of “selectme” to create a subselection, but how can I stop before “irrelevant link 2”?
Have you try to add the response to the HTML document.