How to higlight H2 background color or Text in H2 if I click on numbers 1, 2, 3
This code I use for Quiz system.
If I click on numbers on page, posiotion moved corresponding H2
$(document).on('click', 'a[href^="#"]', function(e) {
var id = $(this).attr('href');
var $id = $(id);
if ($id.length === 0) {
return;
}
e.preventDefault();
var pos = $id.offset().top - 40;
$('body, html').animate({scrollTop: pos});
});
#fora {
position:fixed;
}
#mydiv {
height:1000px;
}
#divforh {
padding-top: 500px;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<html>
</html>
<body>
<div id="fora">
<a href="#1">1</a>,
<a href="#2">2</a>,
<a href="#3">3</a>.
</div>
<div id="mydiv">
<div id="divforh">
<li><h2 id="1">1. Text 1...</h2></li>
<li><h2 id="2">2. Text 2...</h2></li>
<li><h2 id="3">3. Text 3...</h2></li>
</div>
</div>
</body>
Thank you for help