How to get a class from HTML stored in var?

I am looking for a solution to get a class element from HTML stored in var.

I am making an AJAX request that returns the contents of the HTML to me (the "data" argument of the next callback).

$.get(form_action, form_data, function(data){

How can I do something like .hasClass for data to find out if the HTML content matches the .alert class?

I tried '$ (data) .hasClass' and 'data.hasClass', of course, did not work. Any idea?

Antoine

+4
source share
1 answer

to check at the root root level use:

if($($.parseXML(data)).find('.alert').length){ 
  //have element with class alert
}

Working demo

+1
source

All Articles