I want to learn jQuery but I can't figure out why my page keeps refreshing right after the on-click event is done.
The goal with this code is to change the background of DivResult. This works for a split seconds before the page is refreshed. I tried it on different browsers and different computers so i think it's something with my code.
This is my jQuery code:
$(document).ready(function(){
$('#button').on('click',function(){
var kleur = "#" +$('#text').val();
$('#DivResult').css({'background-color': kleur});
});
});
and this is my html file:
<!DOCTYPE html>
<html>
<head lang="en">
<meta charset="UTF-8">
<script src="jQuery_JavaScript_Library_v1.11.3.js"></script>
<script src="script.js"></script>
<link href="style.css" rel="stylesheet">
<title></title>
</head>
<body>
<form>
<input type="text" id="text">
<button id="button">button</button>
</form>
<div id="DivResult"> </div>
</body>
</html>
Many thanks in advance!