Browse: Home / Snippets /

Get quiz object via JavaScript

Contents


Snippet #

Important: All snippets are provided as-is without support or guarantees. These snippets are provided as guidelines for advanced users looking to customize LearnDash. For any additional help or support with these snippets, we recommend reaching out to a LearnDash Expert.

add_action( 'wp_footer', function() {
	?>
	<script>
	jQuery(document).ready(function() {
		// Start by getting the Quiz 'Start' button.
		if ( jQuery('.wpProQuiz_content input.wpProQuiz_button[name="startQuiz"]').length ) {
			// Then get the Quiz wrapper. 
			var quizWrapper = jQuery('.wpProQuiz_content input.wpProQuiz_button[name="startQuiz"]').parents('div.wpProQuiz_content');
			if ( typeof quizWrapper !== 'undefined' ) {
				// As part of the Quiz wrapper there is a data="wpProQuizFront" atrribute added.
				// This is the instance of the wpProQuizFront object. 
				var quizInstance = jQuery(quizWrapper).data('wpProQuizFront');
				if ( typeof quizInstance !== 'undefined' ) {
					// Once we have the quiz instance we can call functions like
					//quizInstance.methode.checkQuestion();
				}
			}
		}
	});
	</script>
	<?php
}, 999 );