I have an ajax request that gets back some html
<div id="test">
</div>
in my success method I have this
$('#test', response).addClass('mytest');
$('#SomethingOnMyPage').after(response);
Yet when I look at it on the page I don’t see mytest. It is like it did not add the class.
I also tried
$(response).filter('div.test').addClass('mytest');
same result
If
div#testis really the outermost HTML element in the response, this is what you need:This is because
$('#test', response)— which is equivalent to$(response).find('#test')— searches for descendants of the outermost element ofresponse; since#testis the outermost element and not a descendant element, that selector won’t match anything.