I’d like to know the number of element with myclass as CSS name are in the value result
$.ajax({
url: 'Home/Index',
type: 'POST',
data: id : 5,
success: function (data) {
//get number of myclass here
}
});
I tried this :
$('.myclass', data).length; but I get 0 all the time
Update1
Output console :
<div class="ui-widget myclass">
<div class="ui-state-error ui-corner-all" style="padding: 0 .7em;">
<p><span id="iconAlert" class="ui-icon ui-icon-alert" style="float: left; margin-right: .3em;"></span>
<strong>Alert:</strong> Sample ui-state-error style.</p>
</div>
</div>
Assuming I’ve understood your question correctly, you need to use
filter:Your current attempt is equivalent to
$(data).find(".myclass")and sincefindlooks at descandants it won’t find any elements at the top level.filteron the other hand, will.