js
var a="World";
$(function(){
$('.redStyle').bind('click', function(){
$(".layer").append(' <p>a</p>'); // где 'а' переменная
});
});
html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<body>
<button class="redStyle">Нажать</button>
<div class="layer" >
<h2 id="h">Teкст </h2>
</div>
<script src="https://code.jquery.com/jquery-3.6.1.min.js" integrity="sha256-o88AwQnZB+VDvE9tvIXrMQaPlFFSUTR+nldQm1LuPXQ=" crossorigin="anonymous"></script>
<script src="script.js"></script>
</script>
</body>
</html>