jquery_T20112 (1)
jquery_T20112 (1)
jquery_T20112 (1)
Practical 7. a)
Solution:
Code:
<!doctype html>
<html>
<head>
<title>Online jQuery Editor</title>
<script src="jquery.js"></script>
<script>
$(document).ready(function() {
{
$("button").click(
function() {
document.write("hello world");
}
);
}
});
</script>
</head>
<body>
<p>Hello! Welcome in Jquery Language!!</p>
<button>Click me</button>
</body>
</html>
Output:
II. Write a Jquery to Select elements by class name,id and element name.
<!DOCTYPE html>
<html>
<head>
<title></title>
<script src="jquery.js"></script>
<script>
$(document).ready(function () {
$(".class1").css("background", "#ADF7F7");
$("#id1").css("background", "#DEC7FF");
$("h2").css("background", "#C5F0D0");
});
</script>
</head>
<body>
<p class="class1">Hello!</p>
<p id="id1">Students</p>
<h2>welcome in jquery Language!!</h2>
</body>
</html>
Output:
III. Write a Jquery to show the use of Click(), hover(), on(), trigger(), off()
events.
Code:
<!DOCTYPE html>
<html>
<head>
<title></title>
<script src="jquery.js"></script>
<script>
$("p").on("click", function () {
$(this).css("background-color", "pink");
});
$("#b2").click(function () {
$("p").off("click");
});
$("#b3").on("click", function () {
$("#t1").hide();
});
$("input").select(function () {
$("input").after(" Text marked!");
});
$("#b4").click(function () {
$("input").trigger("select");
});
});
</script>
</head>
<body>
<button id="b1">hover</button><br />
Code:
<!DOCTYPE html>
<html>
<head>
<title></title>
<script src="jquery.js"></script>
<script>
$(document).ready(function () {
$("#b1").click(function () {
$("p").hide();
});
$("#b2").click(function () {
$("p").show();
});
});
</script>
</head>
<body>
<p>Mulund College Of Commerce</p>
<button id="b1">Hide</button>
<button id="b2">Show</button>
</body>
</html>
Output:
Code:
<!DOCTYPE html>
<html>
<head>
<title></title>
<script src="jquery.js"></script>
<script>
$(document).ready(function () {
$("button").click(function () {
$("p").toggle();
});
});
</script>
</head>
<body>
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do
eiusmod tempor incididunt ut labore et dolore magna aliqua.</p>
Code:
<!DOCTYPE html>
<html>
<head>
<title></title>
<script src="jquery.js"></script>
<script>
$(document).ready(function () {
$(".btn1").click(function () {
$("p").fadeOut();
});
$(".btn2").click(function () {
$("p").fadeIn();
});
});
</script>
</head>
<body>
<p>SIES college of arts science and commerce</p>
Code:
<!DOCTYPE html>
<html>
<head>
<title></title>
<script src="jquery.js"></script>
<script>
$(document).ready(function () {
$(".toggle-btn").click(function () {
$("p").fadeToggle();
});
});
</script>
</head>
<body>
<button type="button" class="toggle-btn">click</button>
<p>This is a paragraph.</p>
<p>This is another paragraph.</p>
</body>
</html>
Output:
Code:
<!DOCTYPE html>
<html>
<head>
<title></title>
<script src="jquery.js"></script>
<script>
$(document).ready(function () {
$(".up-btn").click(function () {
$("p").slideUp();
});
$(".down-btn").click(function () {
$("p").slideDown();
});
});
</script>
</head>
<body>
<button type="button" class="up-btn">Slide Up Paragraphs</button>
<button type="button" class="down-btn">Slide Down
Paragraphs</button>
<p>This is a paragraph.</p>
<p>This is another paragraph.</p>
</body>
</html>
Output:
Slide Up effect
Code:
<!DOCTYPE html>
<html>
<head>
<title></title>
<script src="jquery.js"></script>
<script>
$(document).ready(function () {
$(".toggle-btn").click(function () {
$("p").slideToggle();
});
});
</script>
</head>
<body>
<button type="button" class="toggle-btn">Slide Toggle
Paragraphs</button>
<p>This is a paragraph.</p>
<p>This is another paragraph.</p>
</body>
</html>
Output:
Practical 8.a)
Code:
<!DOCTYPE html>
<html>
<head>
<title></title>
<script src="jquery.js"></script>
<style>
img {
position: relative; /* Required to move element */
}
</style>
<script>
$(document).ready(function () {
$("button").click(function () {
$("img").animate({ left: 300 });
});
});
</script>
</head>
<body>
<button>Start Animation</button><br />
Output:
Code:
<!DOCTYPE html>
<html>
<head>
<title></title>
<script src="jquery.js"></script>
<style type="text/css">
.box {
width: 100px;
Sweta Prajapati, T.20.112
height: 100px;
background: #9d7ede;
margin-top: 30px;
border-style: solid;
border-color: #6f40ce;
}
</style>
<script>
$(document).ready(function () {
$("button").click(function () {
$(".box").animate({
width: "300px",
height: "300px",
marginLeft: "150px",
borderWidth: "10px",
opacity: 0.5,
});
});
});
</script>
</head>
<body>
<button type="button">Start Animation</button>
<div class="box"></div>
</body>
</html>
Output:
Code:
<!DOCTYPE html>
<html>
<head>
<title></title>
<script src="jquery.js"></script>
<script>
$(document).ready(function () {
$("button").click(function () {
$("#p1").css("color", "red").slideUp(2000).slideDown(2000);
});
});
</script>
</head>
<body>
<p id="p1">Welcome in jQuery!!</p>
<button>Click me</button>
</body>
</html>
Output:
Code:
<!DOCTYPE html>
<html>
<head>
<title></title>
<script src="jquery.js"></script>
<script>
$(document).ready(function () {
$("button").click(function () {
$("p").hide("slow", function () {
alert("The paragraph is now hidden");
});
});
});
</script>
</head>
<body>
<button>click</button>
<p>This is a paragraph</p>
</body>
</html>
Output:
Code:
<!DOCTYPE html>
<html>
<head>
<title></title>
<script src="jquery.js"></script>
<script>
$(document).ready(function () {
$(".b1").click(function () {
var str = $("p").text();
alert(str);
});
$(".b2").click(function () {
$("p").text("This is demo text.");
});
});
</script>
</head>
<body>
<button class="b1">Get All Paragraph's Text</button>
<p>This is a paragraph.</p>
<p>This is another paragraph.</p>
Output:
III. Write a Jquery to get and set HTML contents of the elements.
Code:
<!DOCTYPE html>
<html>
<head>
<title></title>
<script src="jquery.js"></script>
<script>
$(document).ready(function () {
$(".b1").click(function () {
var str = $("p").html();
alert(str);
});
$(".b2").click(function () {
$("body").html("<p>Hello World!</p>");
});
});
</script>
</head>
<body>
<button class="b1">Get Paragraph's HTML Contents</button>
<p>The quick <b>brown fox</b> jumps over the lazy dog.</p>
Code:
<!DOCTYPE html>
<html>
<head>
<title></title>
<script src="jquery.js"></script>
<script>
$(document).ready(function () {
$(".b1").click(function () {
var str = $("img#jquery").attr("alt");
alert(str);
});
$(".b2").click(function () {
Output:
I. Write a Jquery to insert HTML elements at the beginning and end of the
elements.
Code:
<!DOCTYPE html>
<html>
<head>
<title></title>
<script src="jquery.js"></script>
<script>
$(document).ready(function () {
$(".b1").click(function () {
$("p").prepend("<strong>Note:</strong> ");
});
$(".b2").click(function () {
$("#container").append("This is demo text.");
});
});
</script>
</head>
<body>
<button class="b1">Insert Text at Begin</button>
<p>welcome in Jquery</p>
Output:
II. Write a Jquery to insert multiple HTML elements at the beginning and end
of the elements.
Code:
<!DOCTYPE html>
<html>
<script>
$(document).ready(function () {
$(".b1").click(function () {
var newHeading = "<h1>Important Note:</h1>";
var newParagraph = document.createElement("p");
newParagraph.innerHTML = "<em>hello world</em>";
$("body").append(newHeading, newParagraph);
});
});
</script>
</head>
<body>
<button class="b1">Insert Contents</button>
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit.</p>
</body>
</html>
Output:
Code:
<!DOCTYPE html>
<html>
<head>
<title></title>
Sweta Prajapati, T.20.112
<script src="jquery.js"></script>
<script>
$(document).ready(function () {
$(".b1").click(function () {
var newHeading = "<h1>Important Note:</h1>";
var newParagraph = document.createElement("p");
newParagraph.innerHTML = "<em>Lorem Ipsum is dummy
text...</em>";
$("p").before(newHeading, newParagraph);
});
$(".b2").click(function () {
var newHeading = "<h1>Important Note:</h1>";
var newParagraph = document.createElement("p");
newParagraph.innerHTML = "<em>Lorem Ipsum is dummy
text...</em>";
$("body").append(newHeading, newParagraph);
});
});
</script>
</head>
<body>
<button class="b1">Insert Contents Begin</button>
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit.</p>
Output:
Insert at end
Code:
<!DOCTYPE html>
<html>
<head>
<title></title>
<script src="jquery.js"></script>
<script>
$(document).ready(function () {
$(".btn").click(function () {
$("div#demo").remove();
});
});
</script>
</head>
<body>
<div id="demo">
Output:
V. Write a Jquery to remove the parent element of an HTML element from the
page.
Code:
<!DOCTYPE html>
<html>
<head>
<title></title>
<script src="jquery.js"></script>
<script>
$(document).ready(function () {
$("button").click(function () {
$("p").unwrap();
});
});
</script>
<style>
div {
<body>
<div>
<p>This is a paragraph inside a div element.</p>
</div>
<article>
<p>This is a paragraph inside an article element.</p>
</article>
Output:
<!DOCTYPE html>
<html>
<head>
<title></title>
<script src="jquery.js"></script>
<script>
$(document).ready(function () {
$("button").click(function () {
$("p").removeAttr("style");
});
});
</script>
<style>
div {
background-color: yellow;
}
article {
background-color: pink;
}
</style>
</head>
<body>
<h1>This is a heading</h1>
<p style="font-size: 120%; color: red">This is a paragraph.</p>
<p style="font-weight: bold; color: blue">This is another
paragraph.</p>
<button>Remove the style attribute from all p elements</button>
</body>
</html>
Output:
Code:
<!DOCTYPE html>
<html>
<head>
<title></title>
<script src="jquery.js"></script>
<script>
$(document).ready(function () {
$("button").click(function () {
$("p").removeClass("intro");
});
});
</script>
<style>
.intro {
font-size: 120%;
color: red;
}
</style>
Sweta Prajapati, T.20.112
</head>
<body>
<h1>This is a heading</h1>
<p class="intro">This is a paragraph.</p>
<p class="intro">This is another paragraph.</p>
Output:
Code:
<!DOCTYPE html>
<html>
<head>
<title></title>
<script src="jquery.js"></script>
<script>
$(document).ready(function () {
$(".b1").click(function () {
$(".box").slideToggle();
Sweta Prajapati, T.20.112
});
});
</script>
</head>
<body>
<button type="button" class="b1">Slide Toggle</button>
<hr />
<div class="box">
<div class="box-inner">
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nam eu
sem
tempor, varius quam at, luctus dui.
</div>
</div>
</body>
</html>
Output:
IX. Write a Jquery to remove the HTML elements from the page.
Code:
<!DOCTYPE html>
<html>
<head>
<title></title>
<script src="jquery.js"></script>
<script>
$(document).ready(function () {
$("button").click(function () {
$("#div1").remove();
});
});
Output: