JQUERY PRACTICALS
JQUERY PRACTICALS
U
jQuery SYLLABUS DEMOS
OOGLE CDN LINK:
G
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.7.1/jquery.min.js"></script>
!DOCTYPE html>
<
<html>
<head>
<title>jquery demo</title>
<script src="C:\Users\Lenovo\Downloads/jquery-3.7.1.min.js"></script>
<script>
$(document).ready(function(){
alert("jQuery via CDN is working!");
});
</script>
</head>
<body>
</body>
</html>
_______________________________________
<!--14-A. Write a JQuery to show the use of ID-->
!DOCTYPE html>
<
<html>
<head>
<title>jquery id demo</title>
<script src="C:\Users\Lenovo\Downloads/jquery-3.7.1.min.js"></script>
<script>
$(document).ready(function()
{
$("button").click(function()
{
$("#a").hide();
});
});
</script>
/head>
<
<body>
<h1>jquery using id selector</h1>
<p> this is a demo lecture </p>
<p id="a"> this line will hide </p>
<p id="a"> this line will be hide when button clicked </p>
<h1> This Line will not hide </h1>
<p> this is a demo lecture </p>
<h1> This Is example </h1>
<button> click here to hide </button>
</body>
</html>
_______________________________________
<!--14-B. Write a JQuery to show the use of Class selector.-->
!DOCTYPE html>
<
<html>
<head>
<title> jquery class selector</title>
<script src="C:\Users\Lenovo\Downloads/jquery-3.7.1.min.js"></script>
<script>
$(document).ready(function()
{
$("button").click(function()
{
$(".a").hide();
});
});
</script>
</head>
<body>
<h1> Jquery using class selector </h1>
<p> this is a demo lecture </p>
<p class="a"> this line will hide </p>
<p class="a"> this line will be hide when button clicked </p>
<h1> This Line will not hide </h1>
<p class="a"> this is a demo lecture </p>
<h1> This Is example </h1>
<button> click here to hide </button>
/body>
<
</html>
_______________________________________
<!--14-C. Write a JQuery to show the use of Tag selector.-->
!DOCTYPE html>
<
<html>
<head>
<title> Jquery using tag selector</title>
<script src="C:\Users\Lenovo\Downloads/jquery-3.7.1.min.js"></script>
<script>
$(document).ready(function(){
$("button").click(function(){
$("p").hide();
});
});
</script>
</head>
<body>
<h1> Jquery using tag selector </h1>
<h2>This is a heading</h2>
<p>This is a paragraph.</p>
<p>This is another paragraph.</p>
<button>Click here to hide</button>
</body>
</html>
_______________________________________
!--15. Write a JQuery to show the use of First, Last and eq selector.-->
<
<!DOCTYPE html>
<html>
<head>
<title> First, Last and eq selector</title>
<script src="C:\Users\Lenovo\Downloads/jquery-3.7.1.min.js"></script>
<script>
$(document).ready(function()
{
$("button").click(function()
{
$ ("p:first").hide();
$("p:last").hide();
$("p:eq(1)").css("background-color","red");
});
} );
</script>
</head>
<body>
<h1>Use of First, Last and eq selector</h1>
<p> This is first Line </p>
<p> This is second Line </p>
<p> This is third Line </p>
<p> This is fourth Line </p>
<p> This is fifth Line </p>
<button> click here </button>
</body>
</html>
_______________________________________
!--16. Write a jQuery for table where oddnoofrowsmustbewithbackgroundcolorin
<
Blue and Even no of rows in Pink color while move mouse on table row it will change
background color green.-->
<!DOCTYPE html>
<html>
<head>
<title> demo 16 - mouse over and mouse out demo</title>
<script src="C:\Users\Lenovo\Downloads/jquery-3.7.1.min.js"></script>
<script>
$(document).ready(function()
{
$("tr:even").css("background-color","pink");
$("tr:odd").css("background-color","lightblue");
$("tr").mouseover(function()
{
$(this).css("background-color","lightgreen");
});
$("tr").mouseout(function()
{
$(this).css("background-color","red");
});
});
/script>
<
</head>
<body>
<h1> student details </h1>
_______________________________________
!--17.Write jQuery for paragraph hide and show when click on title of paragraph that
<
paragraph only show rest of paragraphs will hide make 4 paragraphs with title.-->
!DOCTYPE html>
<
<html>
head>
<
<title> demo 17 - paragraph hide and show</title>
<script src="C:\Users\Lenovo\Downloads/jquery-3.7.1.min.js"></script>
<script>
$(document).ready(function() {
$(".title").click(function(){
$(".paragraph").hide(); // Hide all paragraphs
$(this).next(".paragraph").toggle(); // Show only the clicked paragraph
});
});
</script>
</head>
<body>
h3 class="title">Title 1</h3>
<
<p class="paragraph">This is Paragraph 1 content.</p>
h3 class="title">Title 2</h3>
<
<p class="paragraph">This is Paragraph 2 content.</p>
h3 class="title">Title 3</h3>
<
<p class="paragraph">This is Paragraph 3 content.</p>
h3 class="title">Title 4</h3>
<
<p class="paragraph">This is Paragraph 4 content.</p>
/body>
<
</html>
_______________________________________
!--18.WriteaJQuerytoprintamultiplicationtabletogetdatafromtheuserandmustbe
<
numeric data. Also not allow less than 1 value as input.-->
!DOCTYPE html>
<
<html>
<head>
<title> demo 18</title>
<script src="C:\Users\Lenovo\Downloads/jquery-3.7.1.min.js"></script>
<script>
$(document).ready(function(){
$ ("button").click(function(){
var n=$("#num").val();
if(n!=0)
{
for($i=1; $i<=10; $i++)
{
var tbl=n*$i;
var t=$("#output").append("<tr><td>"+n+"*"+$i+"="+tbl+"</td></tr><br>");
}
}
else
alert("Invalid Output");
});
});
</script>
</head>
<body>
<table id="output">
<tr>
<td>
<h1>Multiplication Table</h1>
</td>
</tr>
<tr><td>
<input type="text" id="num">
<button>Click to See Table</button>
</td>
</tr>
</table>
</body>
</html>
_______________________________________
!--19. Write a jQuery for change the background color of web page, select background
<
color from dropdown list.-->
!DOCTYPE html>
<
<html>
<head>
<title> demo 19</title>
script src="C:\Users\Lenovo\Downloads/jquery-3.7.1.min.js"></script>
<
<script>
$(document).ready(function(){
$("#1").change(function(){
var clr=document.getElementById("1").value;
$("body").css("background-color",clr);
});
});
</script>
</head>
<body>
<select id="1">
<option value="blue">blue</option>
<option value="green">green</option>
<option value="silver">silver</option>
<option value="teal">teal</option>
<option value="red">red</option>
<option value="white">white</option>
<option value="maroon">maroon</option>
<option value="yellow">yellow</option>
</select>
</body>
</html>
_______________________________________
!--20. Write a jQuery to showthefadeeffectonimagewhileuserclickonfadeinimage
<
will show and while click on fade out image will hide.-->
!DOCTYPE html>
<
<html>
<head>
<title>fade in and out image</title>
<script src="C:\Users\Lenovo\Downloads/jquery-3.7.1.min.js"></script>
<script>
$(document).ready(function()
{
$("#b1").click(function()
{
$("#1").fadeIn();
});
$ ("#b2").click(function(){
$("#1").fadeOut();
});
} );
</script>
</head>
<body>
<button id="b1">FADE IN </button>
<button id="b2">FADE OUT </button>
<div>
<div id="1" style="display:none;">
<img src="wallpaper.jpg" height="auto" width="900"></img>
</div>
</div>
</body>
</html>
_______________________________________
!--21.WriteajQuerytocreateadropdownMenuonthefollowinglist.Whileuserclickon
<
SEM1 then SEM1 list only display SEM2 list should not visible
I. SEM1
a. C
b. HTML
c. ICET
d. MATHS
II. SEM2
a. ADV.C
b. DHTML
c. CN
-->
!DOCTYPE html>
<
<html>
<head>
<title> demo 21</title>
<script src="C:\Users\Lenovo\Downloads/jquery-3.7.1.min.js"></script>
<script>
$ (document).ready(function(){
$('#menu1').click(function() {
$('#submenu1').slideToggle(); // Toggle the visibility of Submenu 1
$('#submenu2').slideUp(); // Hide Submenu 2
});
$('#menu2').click(function() {
$('#submenu2').slideToggle(); // Toggle the visibility of Submenu 2
$('#submenu1').slideUp(); // Hide Submenu 1
});
});
</script>
</head>
<body>
<ol type="I">
<li id="menu1">SEM1</li>
<ol type="a" id="submenu1">
<li>C</li>
<li>HTML</li>
<li>ICET</li>
<li>MATHS</li>
</ol>
<li id="menu2">SEM2</li>
<ol type="a" id="submenu2">
<li>ADV.C</li>
<li>DHTML</li>
<li>CN</li>
</ol>
</body>
</html>
_______________________________________
!--22.WriteajQuerytogetthevaluefromcheckboxanddisplayonscreenonlyselected
<
values -->
!DOCTYPE html>
<
<html>
<head>
<title> demo 22</title>
<script src="C:\Users\Lenovo\Downloads/jquery-3.7.1.min.js"></script>
<script>
$(document).ready(function(){
$("button").click(function(){
alert($("input:checkbox:checked").val());
});
});
</script>
</head>
<body>
<input type="checkbox" value="C" > C
<input type="checkbox" value="HTML"> HTML
<input type="checkbox" value="java"> java
<input type="checkbox" value="PHP"> PHP
<button>Click</button>
</body>
</html>
_______________________________________
<!--23. Write a jQuery to get Value from Radio button and display on Screen. -->
!DOCTYPE html>
<
<html>
<head>
<title> demo 24</title>
<script src="C:\Users\Lenovo\Downloads/jquery-3.7.1.min.js"></script>
<script>
$(document).ready(function(){
$("button").click(function(){
alert($("input:radio[name=rdbtn]:checked").val());
});
});
</script>
</head>
<body>
<input type = "radio" name = "rdbtn" value = "female" >Female<br/><br/>
<input type = "radio" name = "rdbtn" value = "male" >Male<br/><br/>
<button>Click here</button>
</body>
</html>
_______________________________________
<!--24.Write a jQuery to copy fullname, Address, mobile number on Keyboard Event. -->
!DOCTYPE html>
<
<html>
<head>
<title> demo 24</title>
<script src="C:\Users\Lenovo\Downloads/jquery-3.7.1.min.js"></script>
<script>
$(document).ready(function(){
$("input").keyup(function() {
// Get the values from the input fields
var fullName = $("#fullname").val();
var address = $("#address").val();
var mobileNumber = $("#mobile").val();
// Display the copied values in the output paragraph
$("#output").text("Full Name: " + fullName + "\nAddress: " + address +
"\nMobile Number: " + mobileNumber);
});
});
</script>
</head>
<body>
<p>Full Name: <input type="text" id="fullname" ></p>
<p>Address: <input type="text" id="address"></p>
<p>Mobile Number: <input type="text" id="mobile" ></p>
<p id="output"></p>
</body>
</html>
_______________________________________
!--25.WriteajQuerycodeforverifiesfirstpasswordandsecondpasswordissameornote.
<
Verify the strength of password in week, medium and strong.-->
OTE:Directlychecksforatleastoneuppercaseletter([A-Z]),onelowercaseletter([a-z]),
N
one number ([0-9]), and one special character ([^a-zA-Z0-9]).
!DOCTYPE html>
<
<html>
<head>
<title>Demo25</title>
script src="C:\Users\Lenovo\Downloads/jquery-3.7.1.min.js"></script>
<
</head>
<body>
<script>
$(document).ready(function(){
$("#password").keyup(function(){
var password = $(this).val();
var numbers = /[0-9]/;
var uppercaseLetters = /[A-Z]/;
var lowercaseLetters = /[a-z]/;
var specialCharacters = /[^a-zA-Z0-9]/;