I have a div tag which contains the Content as “I am div tag”.When i was trying to Toggle this div when a user click on button. here is the code which i wrote
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>jquery effects (Hide,Animate,SlideDown,SlideUp)</title>
<style type="text/css">
.togg
{
background-color: Aqua;
}
</style>
<script type="text/javascript" src="http://code.jquery.com/jquery-1.4.1.js">
$(document).ready(function () {
$("p").click(function () {
$(".togg").toggle();
});
});
</script>
</head>
<body>
<div class="togg">
I am a Div Tag
<p>
hi Laxmi ! how r u?</p>
</div>
</body>
</html>
am not getting the output here.But when i write the code like this here am getting the output.please tell me the difference between these lines of code
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>jquery effects (Hide,Animate,SlideDown,SlideUp)</title>
<style type="text/css">
.togg
{
background-color: Aqua;
}
</style>
<script type="text/javascript" src="http://code.jquery.com/jquery-1.4.1.js"></script>
<script type="text/javascript">
$(document).ready(function () {
$("p").click(function () {
$(".togg").toggle();
});
});
</script>
</head>
<body>
<div class="togg">
I am div Tag
<p>
hi Laxmi! how r u?</p>
</div>
</body>
</html>
First piece of code contains an error. You can’t include javascript files (by putting their paths in
srcattribute ofscripttag) and then put the code inside it.Just use the second code.