Вопрос

I have this array:

var arr  = ['<p id="p1">Paragraph 1<p>', '<p id="p2">Paragraph 2<p>', '<p id="p3">Paragraph 3<p>']

How can I get the text Paragraph 3 from this array?

Это было полезно?

Решение

You can use:

$(arr[2]).prop('innerHTML');

or:

$(arr[2]).html();

Fiddle

Другие советы

You can strip the inner text by chopping up the string using the split() method.

<script>

var arr  = ['<p id="p1">Paragraph 1<p>', '<p id="p2">Paragraph 2<p>', '<p id="p3">Paragraph 3<p>']

/* Even works with closed <p> element */

var arr  = ['<p id="p1">Paragraph 1</p>', '<p id="p2">Paragraph 2</p>', '<p id="p3">Paragraph 3</p>']

alert(arr[2].split('>')[1].split('<')[0])
</script>
Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top