How can I insert jquery inside an html tag like using it in onclick. For example how can I insert this jquery function inside html?
<html>
<head>
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript">
$(document).ready(function(){
$("button").click(function(){
$("p").slideToggle();
});
});
</script>
</head>
<body>
<p>This is a paragraph.</p>
<button>Toggle between slide up and slide down for a p element</button>
</body>
</html>
Putting the body of your function directly in the
onclickattribute of thebuttontag works.However, I think the way you have it is a preferable way to do it, since it takes advantage of the
$(document).readyfunction.