I can't figure out why, but scrollIntoView()
function doesn't work. The browser displays an error: Uncaught TypeError: element.scrollIntoView is not a function at ...
. The element element
is defined and displayed in console. I haven't been able to find any answer in the Internet. Below is simplified code:
[...]
<table>
<thead>
<tr>
<th>ID</th>
<th>Name</th>
<th>Surname</th>
</tr>
</thead>
<tbody>
<?php
if (is_array($array)) {
foreach ($array as $element) { ?>
<tr data-someid="<?= $element->some_id ?>">
<th><?= $element->id ?></th>
<td><?= $element->name ?></td>
<td><?= $element->surname ?></td>
</tr>
<?php }
} ?>
</tbody>
</table>
[...]
<script>
var element= document.querySelectorAll('[data-someid="' + someId + '"]');
console.log(element); // displays the element well
element.scrollIntoView();
</script>
[...]
Do somebody have any ideas why it doesn't work?
I can't figure out why, but scrollIntoView()
function doesn't work. The browser displays an error: Uncaught TypeError: element.scrollIntoView is not a function at ...
. The element element
is defined and displayed in console. I haven't been able to find any answer in the Internet. Below is simplified code:
[...]
<table>
<thead>
<tr>
<th>ID</th>
<th>Name</th>
<th>Surname</th>
</tr>
</thead>
<tbody>
<?php
if (is_array($array)) {
foreach ($array as $element) { ?>
<tr data-someid="<?= $element->some_id ?>">
<th><?= $element->id ?></th>
<td><?= $element->name ?></td>
<td><?= $element->surname ?></td>
</tr>
<?php }
} ?>
</tbody>
</table>
[...]
<script>
var element= document.querySelectorAll('[data-someid="' + someId + '"]');
console.log(element); // displays the element well
element.scrollIntoView();
</script>
[...]
Do somebody have any ideas why it doesn't work?
Share Improve this question edited Feb 2, 2019 at 14:24 Andrew Shaban asked Feb 2, 2019 at 14:13 Andrew ShabanAndrew Shaban 1372 silver badges16 bronze badges1 Answer
Reset to default 4document.querySelectorAll()
returns a list of DOM elements. Right now you're trying to access a method .scrollIntoView
on the returned NodeList
which of course doesn't exist.
You probably meant to use document.querySelector()
which returns a single element.
发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745284392a4620473.html
评论列表(0条)