Javascript-форум (https://javascript.ru/forum/)
-   Javascript под браузер (https://javascript.ru/forum/css-html/)
-   -   перебрать элементы строки (https://javascript.ru/forum/css-html/70361-perebrat-ehlementy-stroki.html)

atanov 30.08.2017 17:36

перебрать элементы строки
 
Вот такой ещё вопрос:

взяли все элементы с тегом tr:

var rw = document.getElementsByTagName('tr');


что-то туплю, как в rw перебрать последовательно все его элементы (может быть <th>, <td>)?

рони 30.08.2017 19:20

atanov,
rw[index].children или rw[index].cells

j0hnik 30.08.2017 23:27

<html>
<head>
</head>
<body>
<table>
	<tr><td>1<td>2
	<tr><td>3<td>4
</table>
		<script>	
[].forEach.call(document.querySelectorAll('tr>*'), function(el){
	alert(el.textContent);
});
		</script>
</body>
</html>

atanov 01.09.2017 10:46

Спасибо!


Часовой пояс GMT +3, время: 16:03.