Professional Documents
Culture Documents
BikarajSIngha (CAP214)
BikarajSIngha (CAP214)
class Bika{
constructor(){
this.height = 171,
this.age = 19
}
}
const a = new Bika();
a.height;
>>171
Q3. How does jQuery events change the behavior of the HTML web
page? Explain it with the help of an example.
Ans.
jQuery events provide a function for a specific event, so the provided
function is executed when a particular event take place. Examples of
events are a mouse click, an HTML form submission, a web page
loading, a keystroke on the keyboard etc. jQuery events helps to specify
a way how a HTML web page reacts to an event.
Example:
To assign a click event to all italic texts on a page:
$(“i”).click ();
The next step is to define what should happen when the event fires. So
we have to pass a function to the event:
$(“i”).click(function(){
//some action goes Here
}
Some other methods are as follows:
$(document).ready() method allow us to execute a function the
document is fully loaded.
click() method attaches an event handler function to an HTML element.
This function is executed when the user clicks on the HTML element.
Mouseenter() method attaches an event handler function to an HTML
element. The function is executed when the mouse pointer enters the
HTMl element
Q4. Write a program in JavaScript to find the number entered by user
is prime or not.
Ans.
<html> <head> <script>
// Function to check prime number
function p() {
var n, i, flag = true;
n = prompt(“Enter Number”);
n = parseInt(n);
for(i = 2; i <= n - 1; i++)
if (n % i == 0) {
flag = false;
break;
}
// Check and display alert message
if (flag == true)
alert(n + " is prime");
else
alert(n + " is not prime");
}
</script> </head> <body>
<h1>check number is prime or not</h1>
<hr>
<form>
<input type="button" value="ClickHererToCheck" onClick="p()">
</form> </body> </html>