A Zakaria
A Zakaria

Reputation: 35

JQuery .get data count

I have a file (aa.html) contains the following:

 <p> Item1 </p>
 <p> Item2 </p>
 <p> Item3 </p>

I was able to read it using this:

$.get('aa.html', function(data) {
alert(data);
});

how can I know the number of Items inside (or count number of <p>)?

Upvotes: 1

Views: 563

Answers (1)

Lee
Lee

Reputation: 13542

$.get('aa.html', function(data) {
  var dom = $('<div/>').append(data);
  alert("# of <p> elements: " + dom.find('p').length);
});

Upvotes: 1

Related Questions