diff --git a/mod/book/templates/main_action_menu.mustache b/mod/book/templates/main_action_menu.mustache
index 282a64a9554..fcc206f9814 100644
--- a/mod/book/templates/main_action_menu.mustache
+++ b/mod/book/templates/main_action_menu.mustache
@@ -42,12 +42,12 @@
{{#previous}}
{{/previous}}
{{#next}}
{{/next}}
diff --git a/mod/book/view.php b/mod/book/view.php
index 57082db6939..68597a32fef 100644
--- a/mod/book/view.php
+++ b/mod/book/view.php
@@ -123,7 +123,7 @@ if (!$chapterid) {
$renderer = $PAGE->get_renderer('mod_book');
$actionmenu = new \mod_book\output\main_action_menu($cm->id, $chapters, $chapter, $book);
$renderedmenu = $renderer->render($actionmenu);
- echo $renderedmenu;
+ echo html_writer::div($renderedmenu, '', ['id' => 'mod_book-chaptersnavigation']);
// The chapter itself.
$hidden = $chapter->hidden ? ' dimmed_text' : null;