Browse: Home / Snippets /

Get quiz object via JavaScript

Contents


Snippet #

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 );