CSS Question Bank For UT2 by JN

Download as pdf or txt
Download as pdf or txt
You are on page 1of 25

Unit 3:

1. What is Intrinsic Java functions?


ANS. : - JavaScript has a special set of functions called
intrinsic functions that mimic actions of the Submit button and
Reset button of a form.
- You don’t define an intrinsic function, because JavaScript
defines the function for you.
- However, you can call an intrinsic function in the same way
you would if you had defined the function.
- An intrinsic function is often used to replace the Submit button
and the Reset button with your own graphical images, which are
displayed on a form in place of these buttons.
- This is illustrated in the next example.
- Two Error! Filename not specified.(image) tags are used:
one to display submit.jpg and the other to display reset.jpg.
- Notice that each of these traps the onclick event and calls the
appropriate intrinsic function.
- This has the same effect as inserting the Submit and Reset
buttons on the form and then clicking them.
2. Explain changing attribute value dynamically with
example.
ANS. : In javascript we can change the value of any form
elements dynamically. For example - if element is loaded with
default value at the time of page load, then the values can be
change at runtime and we can notify to the user the
Importance of alteration/modification in form element values.
We can change an attribute of an element by assigning a new
value to that attribute in a JavaScript function and function
can be called when an appropriate event occurs.
EXAMPLE :-
<html>
head>
<script language="javascript" type="text/javascript">
function display() {
document.forms.VJTech.myMassage.value = "WelCome - "+
document.forms.VJTech.fname.value;
}
</script></head>
<body>
<form name="VJTech">
First Name : <input type="text" name="fname"
onkeyup="display()"
/><br><b<r>
Message : <input type="text" name="myMassage" />
</form>
</body>
</html>
Unit 4:
1. What is cookie and give its types
ANS. : The user information present in web pages can be stored
by using cookie. Cookie is a small piece of information sent
from the website and stored in a file on the user's computer. The
information sent from the website is specific to a user.lt is stored
by the user's web browser, and web browser can access that
information.

Types of cookies:
1. Session Cookies
2. Presistent Cookies

2.Explain Browser object with diagram.


ANS. : The Browser Object Model (BOM) is a set of
properties, rules, and methods in JavaScript that is used for
containing all the information related to the browser and screen
of a computer that we see at that instant of time. There is much
information that we can fetch with the help of the Window
Object Model in JavaScript Like, - We can find the browser
name that we are using currently, we can open new one or more
at a time windows, we can find the dimension of that window
screen, the page history like which page we are using before
coming to the present page, etc.
Diagram of browser object :

3. Explain document object with diagram.


ANS. : In JavaScript, the Document Object Model (DOM) represents
the structure of a web document. The document object is a property of
the global window object and serves as the entry point to the web page's
content.

Here is an explanation of the document object along with a diagram:


The document Object

The document object represents the entire HTML document. It is the


root node of the DOM tree and provides various properties and methods
to interact with the HTML content. Some of the key properties and
methods include:

 Properties:
o document.title: Gets or sets the title of the document.
o document.body: Represents the <body> element of the
document.
o document.head: Represents the <head> element of the
document.
o document.URL: Returns the URL of the document.
o document.cookie: Gets or sets cookies associated with the
document.
 Methods:
o document.getElementById(id): Returns the element with the
specified ID.
o document.getElementsByClassName(className): Returns a
collection of elements with the specified class name.
o document.getElementsByTagName(tagName): Returns a
collection of elements with the specified tag name.
o document.querySelector(selector): Returns the first element
that matches the specified CSS selector.
o document.querySelectorAll(selector): Returns a collection of
elements that match the specified CSS selector.
o document.createElement(tagName): Creates a new
element with the specified tag name.
o document.createTextNode(text): Creates a new text
node with the specified text.
Diagram of document :

4.How to read a cookie value. Explain with example


ANS. :
-To read cookies, you can access the document.cookie
property.
- Cookies are stored as a single string, with multiple
cookies separated by semicolons and spaces.
-For Example : var cookie_string = document.cookie;// it
will return all cookies in string format and it separates
using semicolon
-You typically split the string to extract individual cookie
values.
-For Example :
var cookie_array = document.cookie.split(';'); for(var i = 0;
i < cookie_array.length; i++) {
document.write(cookie_array[i] + "
"); }
-This code will split all cookies with semicolon and store in
array and then print all cookies in new line.
- If there are no cookies, ‘document.cookie’ will return an empty
string.

5. What is the use scrollTo() function?


ANS. : The scrollTo() method of the Element interface scrolls
to a particular set of coordinates inside a given element.
SYNTAX :
scrollTo(xCoord, yCoord)
scrollTo(options)
PARAMETERS :
xCoord

The pixel along the horizontal axis of the element that you
want displayed in the upper left.
yCoord
The pixel along the vertical axis of the element that you
want displayed in the upper left.
options
An object containing the following properties:
top
Specifies the number of pixels along the Y axis to scroll the
window or element.
left
Specifies the number of pixels along the X axis to scroll the
window or element.
behavior
Determines whether scrolling is instant or animates
smoothly. This option is a string which must take one of the
following values:
 smooth: scrolling should animate smoothly
 instant: scrolling should happen instantly in a single
jump
 auto: scroll behavior is determined by the computed
value of scroll-behavior
EXAMPLE :
JS
element.scrollTo(0, 1000);
Using options:
JS
element.scrollTo({
top: 100,
left: 100,
behavior: "smooth",
});

6. How to open a window. Describes various styles


of window.
ANS. :

8. What is the use scrollBy() function?


ANS. : The Window.scrollBy() method scrolls the document
in the window by the given amount.
Syntax
JS
scrollBy(xCoord, yCoord)
scrollBy(options)
Parameters
xCoord

The horizontal pixel value that you want to scroll by.


yCoord

The vertical pixel value that you want to scroll by


options
An object containing the following properties:
top
Specifies the number of pixels along the Y axis to scroll the
window or element.
left
Specifies the number of pixels along the X axis to scroll the
window or element.
behavior
Specifies whether the scrolling should animate smoothly
(smooth), happen instantly in a single jump (instant), or let
the browser choose (auto, default).
Examples

To scroll down one page:


window.scrollBy(0, window.innerHeight);

To scroll up:
window.scrollBy(0, -window.innerHeight);
Using options:
window.scrollBy({
top: 100,
left: 100,
behavior: "smooth",
});
Unit 5:
1. What is regular expression? Explain with
example.
ANS : Regular expression (regex) is a sequence of
characters that define a search pattern. It is used to search,
edit, or manipulate text and data. Regex is used in many
different programming languages and text editors.

2. Explain the language of regular expression.


ANS. : Regular expressions (regex) in JavaScript are
powerful tools used for pattern matching and manipulation of
strings. They allow you to search, replace, and manipulate
text based on specific patterns. Here's a explanation of the
language of regular expressions in JavaScript:
Basic Syntax

1. Literal Characters:
o Matches exact characters, e.g., /a/ matches "a".
2. Special Characters:
o . matches any character except newline.
o \ escapes special characters, e.g., \. matches a literal dot.
3. Character Classes:
o [abc]: Matches any one of the characters a, b, or c.
o [^abc]: Matches any character except a, b, or c.
o [a-z]: Matches any lowercase letter.
o [0-9]: Matches any digit.
4. Predefined Classes:
o \d: Any digit.
o \D: Any non-digit.
o \w: Any word character (alphanumeric + underscore).
o \W: Any non-word character.
o \s: Any whitespace character.
o \S: Any non-whitespace character.
5. Anchors:
o ^: Start of string.
o $: End of string.
6. Quantifiers:
o *: 0 or more times.
o +: 1 or more times.
o ?: 0 or 1 time.
o {n}: Exactly n times.
o {n,}: n or more times.
o {n,m}: Between n and m times.
7. Grouping & Alternation:
o (abc): Groups abc.
o a|b: Matches a or b.
Flags

 g: Global search.
 i: Case-insensitive.
 m: Multi-line.
 s: Dot matches newline.
 u: Unicode.
 y: Sticky.

3. Write a short note on frame.


ANS. : In HTML and JavaScript, frames are a way to divide a
web page into multiple independent sections, each of which can
display a separate HTML document or web page. Frames were
widely used in early web development but have become less
common due to various limitations and compatibility issues.
Instead, modern web development often relies on other
techniques like CSS layouts, JavaScript frameworks and
iframes. However, it's still useful to understand how frames
work in HTML and JavaScript.

4. What is rollover? explain with example.


ANS. : -Rollover is a JavaScript/Web technique used by Web
developers to produce an effect in which the appearance of a
graphical image changes when the user rolls the mouse pointer
over it.
- Rollover also refers to a button on a Web page that allows
interactivity between the user and the Web page.
- It causes the button to react by either replacing the source
image at the button with another image or redirecting it to a
different Web page.
EXAMPLE CODE :
?

5. Write a javascript code to match a character in a


range of characters.
ANS. :
6. Write a JavaScript code to replace following
string using regular expression.
Original string: Student has PHP textbook
Replace string: Student has JavaScript textbook
ANS. :
7. What is frame? How to create a frame? Explain
with example.
ANS. :
Frames : In HTML and JavaScript, frames are a way to
divide a web page into multiple independent sections, each
of which can display a separate HTML document or web
page. Frames were widely used in early web development
but have become less common due to various limitations
and compatibility issues. Instead, modern web development
often relies on other techniques like CSS layouts and
iframes. However, it's still useful to understand how frames
work in HTML and JavaScript.
Creating Frame :To create frames in HTML, you use the
element. Inside the , you define individual frames using the or
elements. The element is used to define the layout of frames on
a web page.
8. What will be the output?

ANS. :

The Name of city: Mumbai

9. What will be the output after clicking on Try it


Button?

ANS. : Please visit W3Schools!


UNIT 6 :

1. What is status bar and give its syntax.


ANS. : -The JavaScript status bar is a thin horizontal bar at the
bottom of the browser window that can be used to display
information to the user.
- It is typically used to display the status of a loading page, the
filename of a linked file, or the coordinates of the mouse cursor.
- Statusbar is accessed through the window.status property.
- To set the text in the status bar, simply assign a string to the
window.status property.
SYNTAX : window.status
2. What is statusbar explain it with example.
ANS. : -The JavaScript status bar is a thin horizontal bar at the
bottom of the browser window that can be used to display
information to the user.
- It is typically used to display the status of a loading page, the
filename of a linked file, or the coordinates of the mouse cursor.
- Statusbar is accessed through the window.status property.
- To set the text in the status bar, simply assign a string to the
window.status property.
3. How to create a slide show? Explain with
example.
ANS. : - A slideshow is similar in concept to a banner
advertisement in that a slideshow rotates multiple images on the
web page. However, unlike a banner advertisement.
- A slideshow gives the visitor the ability to change the image
that's displayed: the visitor can click the Forward button to see
the next image and the Back button to see the previous image.
EXAMPLE :
4. What is Banner? Explain with example.
ANS. : In web development, a banner is typically a graphic or
image that is prominently displayed at the top of a webpage. It
can be used for advertising, branding, or to convey important
messages or promotions.
EXAMPLE :
5.What is popup menu?
ANS. : - A pop-up menu, also known as a context
menu or right-click menu, is a menu that appears
when a user interacts with a specific element,
typically by right-clicking it.
- Pop-up menus provide context-specific options and
actions based on the user's interaction with the
element.
- Typical Use Cases: Pop-up menus are commonly used in
applications for performing actions on items in a list, table rows,
or any interactive elements. They offer a convenient and
unobtrusive way to access actions.
- Creating Pop-Up Menus: Pop-up menus can be created using a
combination of HTML, CSS, and JavaScript. The HTML
structure includes the menu items, CSS styles control its
appearance, and JavaScript handles event listeners and
interactions.

You might also like