Ap333
Ap333

Reputation: 47

Select all divs with class from var

I need to select all divs with class="test" from a variable and put them into another div.

var all = xmlhttp.responseText;
var x = $(all > '.test');    <-- how to write correctly ?
$('.anotherdiv').prepend(x);

Upvotes: 0

Views: 70

Answers (2)

A. Wolff
A. Wolff

Reputation: 74420

Using jQuery filter() method:

var x = $(all).filter('div.test');

Or using find():

var x = $(all).find('div.test');

Now it depends value of your string all

Upvotes: 1

adeneo
adeneo

Reputation: 318242

$('<div />', {html : all}).find('.test').prependTo('.anotherdiv');

Upvotes: 4

Related Questions