Web Development Day4 Assignment
Web Development Day4 Assignment
class Person {
constructor(name, age) {
this.name = name;
this.age = age;
}
}
class Employee extends Person {
constructor(name, age, jobTitle) {
super(name, age);
this.jobTitle = jobTitle;
}
-------------------------------------------------------
2.DOM events
onclick
onmouseover
onmouseout
onchange
onload
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>ASSIGNMENT</title>
<script src="main.js"></script>
</head>
<body>
<button id="myButton" onclick="alert('Button Clicked')">Click Me</button>
<div id="myDiv" onmouseover="changeColor('green')"
onmouseout="changeColor('black')">Hover Over Me</div>
<select id="mySelect" onchange="alertSelection()">
<option value="option1">Option 1</option>
<option value="option2">Option 2</option>
<option value="option3">Option 3</option>
</select>
</body>
</html>
JS File:
function changeColor(color) {
document.getElementById("myDiv").style.color = color;
}
function alertSelection() {
var select = document.getElementById("mySelect");
var selectedOption = select.options[select.selectedIndex].value;
alert("Selected option: " + selectedOption);
}
window.onload = function() {
alert("Page loaded");
}
--------------------------------------
3. Create Array in javascript and apply following methods
Arrays methods
push
pop
shift
unshift
concat
splice
slice
sort
numbers.push(6);
console.log(numbers);
numbers.pop();
console.log(numbers);
numbers.shift();
console.log(numbers);
numbers.unshift(1);
console.log(numbers);
numbers.splice(2, 0, 6, 7);
numbers.splice(2, 2);
let subNumbers = numbers.slice(1, 3);
console.log(subNumbers);
numbers.sort();
console.log(numbers);
-----------------------------------------------------------------------------------
-------
4.Date Object and methods of date getFullYear()
getMonth()
getDate() Get day as a number (1-31)
getDay() Get weekday as a number (0-6)
getHours() Get hour (0-23)
getMinutes() Get minute (0-59)
getSeconds() Get second (0-59)
getMilliseconds() Get millisecond (0-999)
getTime() Get time (milliseconds since January 1, 1970)
5.)create a jquery code which hide a paragraph on click of hide button and shows
the paragraph on
click of show button
<!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>
<script
src="https://ajax.googleapis.com/ajax/libs/jquery/3.6.1/jquery.min.js"></script>
<script>
$(document).ready(function () {
$("#hide-button").click(function () {
$("p").hide();
});
$("#show-button").click(function () {
$("p").show();
});
});
</script>
</head>
<body>
<button id="hide-button">Hide</button>
<button id="show-button">Show</button>
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Placeat tenetur
dolore quidem beatae earum nesciunt.</p>
</body>
</html>
-----------------------------------------------------------------------------------
----------------------------------------
6.)create a jquery which changes the text and fontcolor of a paragraph on mouser
and on mouseout
<!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>
<script
src="https://ajax.googleapis.com/ajax/libs/jquery/3.6.1/jquery.min.js"></script>
<script>
$(document).ready(function(){
$("p").mouseover(function(){
$(this).text("New text on mouseover");
$(this).css("color", "red");
});
$("p").mouseout(function(){
$(this).text("Original text on mouseout");
$(this).css("color", "black");
});
});
</script>
</head>
<body>
<!-- <button id="hide-button">Hide</button>
<button id="show-button">Show</button> -->
<p style="color: black;">Lorem ipsum dolor sit amet, consectetur adipisicing
elit. Placeat tenetur dolore quidem beatae earum nesciunt.</p>
</body>
</html>
7.)Apply different effects on elements like
slideup,slidedown,animate,stop,fade
toggle
and callfunction to implemented
<!DOCTYPE html>
<html>
<head>
<script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
<script>
$(document).ready(function () {
$("#slideUpBtn").click(function () {
$("#element1").slideUp();
}); $("#slideDownBtn").click(function () {
$("#element1").slideDown();
}); $("#animateBtn").click(function () {
$("#element2").animate({ width: "300px" });
}); $("#stopBtn").click(function () {
$("#element2").stop();
}); $("#fadeOutBtn").click(function () {
$("#element3").fadeOut();
}); $("#fadeInBtn").click(function () {
$("#element3").fadeIn();
}); $("#toggleBtn").click(function () {
$("#element4").toggle();
}); $("#element5").click(function () {
alert("Element clicked!");
});
});</script>
</head>
</html>
-----------------------------------------------------------------------------------
----------------------------------------------------
8)write a jquery code demonstrating travering like
first(),parent(),next()
jquery filtering
first(), last(), eq(), filter() and not() Methods
<!DOCTYPE html>
<html>
<head>
<script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
<script>
$(document).ready(function () {
// Traversing
$("#firstBtn").click(function () {
$("#list").find("li").first().css("background-color", "yellow");
}); $("#parentBtn").click(function () {
$("#list").find("li").parent().css("background-color",
"lightblue");
}); $("#nextBtn").click(function () {
$("#list").find("li").next().css("background-color", "pink");
}); // Filtering
$("#firstBtn").click(function () {
$("#list").find("li").first().css("background-color", "yellow");
}); $("#lastBtn").click(function () {
$("#list").find("li").last().css("background-color", "green");
}); $("#eqBtn").click(function () {
$("#list").find("li").eq(2).css("background-color", "orange");
}); $("#filterBtn").click(function () {
$("#list").find("li").filter(".special").css("background-color",
"purple");
}); $("#notBtn").click(function () {
$("#list").find("li").not(".special").css("background-color",
"gray");
});
});</script>
</head>
<body><button id="firstBtn">First</button><button
id="parentBtn">Parent</button><button
id="nextBtn">Next</button><button id="lastBtn">Last</button><button
id="eqBtn">Eq</button><button
id="filterBtn">Filter</button><button id="notBtn">Not</button>
<ul id="list">
<li>Item 1</li>
<li class="special">Item 2</li>
<li>Item 3</li>
<li>Item 4</li>
<li>Item 5</li>
</ul>
</body>
</html>