JC Web
JC Web
Structure of HTML
Unit -1
1).Structure of HTML
Understanding these key tags will allow you to organize content effectively and create more readable
and accessible webpages.
• Headings (<h1> to <h6>): Headings are important for structuring the content within
the <body> section. They define the hierarchy of information, where <h1> is the highest-
level heading.
• Paragraphs (<p>): The <p> tag is used for creating paragraphs, which help to group text
into readable sections. This tag automatically adds some spacing between paragraphs to
improve readability.
• Images (<img>): The <img> tag is used to add images to a webpage. It requires the src
attribute to specify the image path and the alt attribute for accessibility.
• Links (<a>):Links are created with the <a> tag. The href attribute defines the destination
URL, and the text within the <a> tag serves as the clickable link text.
• Lists (<ul>, <ol>, <li>): Lists allow you to organize items in bullet
points (<ul>) or numbered order (<ol>). Each item within a list is wrapped in <li> tags.
• Divisions (<div>): The <div> tag is a container used to group other elements together,
often for layout. It does not add any style or structure on its own but is useful for applying
CSS styles to sections of content.
HTML offers web authors three ways for specifying lists of information. All lists must contain one or
more list elements.
In the ordered HTML lists, all the list items are marked with numbers by default. It is known as
numbered list also. The ordered list starts with <ol> tag and the list items start with <li> tag.
<html>
<head>
</head>
<body>
<ol>
<li>DBMS</li>
<li>SOFTWARE ENGINEERING</li>
<li>JAVA</li>
<li>WEB TECHNOLOGY</li>
</ol>
</body>
</html>
In HTML Unordered list, all the list items are marked with bullets. It is also known as bulleted list
also. The Unordered list starts with <ul> tag and list items start with the <li> tag.
<html>
<head>
</head> <body>
<ul>
<li>DBMS</li>
<li>SOFTWARE ENGINEERING</li>
<li>JAVA</li>
<li>WEB TECHNOLOGY</li>
</ul>
</body>
</html>
The <dl> tag defines the description list, the <dt> tag defines the term (name), and the <dd> tag describes
each term:
<head>
<title>HTML Definition
List</title>
</head>
<body>
<dl>
<dt><b>HTML</b></dt>
Language</dd>
<dt><b>HTTP</b></dt>
Protocol</dd>
</dl>
</body>
</html>
1.Inline CSS
Inline CSS is generally used to style a specific HTML element only. We can write inline CSS simply
For Example:
<h1 style="background-color:yellow;"> This is a heading </h1>
This CSS type is not really recommended, as each HTML tag needs to be styled individually.
Advantages
• You can easily and quickly write inline CSS to an HTML page.
• It is useful for testing or previewing the changes, and performing quick fixes to your website.
• You don’t need to create or link a separate document as required in the external CSS.
Disadvantages
• Generally, Inline CSS needs to write in each HTML tag individually. So managing a website
may be difficult if we use only inline CSS.
• Adding CSS property to every HTML tag is time-consuming.
• Styling multiple elements can affect your page’s size and download time.
Example
<!DOCTYPE html>
<html>
<body>
</body>
</html>
2.Internal CSS
Internal CSS is also known as embedded CSS. It is generally used to style a single page. We can
write internal CSS inside a <style> tag within the HTML pages.
For Example:
<style>
h1{
background-color : yellow;
color : red;
</style>
This CSS type is an effective method of styling a single page. However, using this style for multiple
pages is time-consuming as you need to put CSS style on every page of your website.
Advantages
• You can use ID and class selectors to write the internal CSS.
• Since you’ll only add the code within the same HTML file, you don’t need to create or upload
multiple files.
Disadvantages
• Since you’ll only add the code within the same HTML file, styling multiple pages will become
time-consuming.
• Adding the code to the HTML document can increase the page’s size and loading time.
Example
<!DOCTYPE html>
<html>
<head>
<style>
h1{
background-color:orange;
.box{
height:200px;
width:300px;
background-color:yellow;
#circle{
height:200px;
width:200px;
background-color:red;
border-radius:50%;
</style>
</head>
<body>
<div class="box"></div>
<div id="circle"></div>
</body>
</html>
External CSS
With an external CSS, you can change the look of an entire website by changing just one file. We
can write external CSS in a separate .css file. Each HTML page must include a reference to
the external CSS file inside the <link> tag, inside the <head> tag.
For Example:
h1{
background-color:orange;
.box{
height:200px;
width:300px;
background-color:yellow;
#circle{
height:200px;
width:200px;
background-color:red;
border-radius:50%;
Now include the my-style.css external file in your HTML page using <link> tag:
<link rel="stylesheet" type="text/css" href="my-style.css" />
<!DOCTYPE html>
<html>
<head>
</head>
<body>
<div class="box"></div>
<div id="circle"></div>
</body>
</html>
Advantages
• Since the CSS code is in a separate file, your HTML files will have a cleaner structure and be
smaller in size.
• You can use the same .css file for multiple pages when you want the same look for each page.
Disadvantages
• Your pages may not be rendered correctly until the external CSS is loaded.
• Uploading multiple external CSS files can increase the download time of a website.
CSS (Cascading Style Sheets) selectors are patterns used to select and style HTML elements. They
allow you to target specific elements on a web page and apply styles to them. Here are some
2. Type Selector:
3. Class Selector:
4. ID Selector:
5. Child Selector:
parent > child: Selects all direct children of the specified parent.
element ~ sibling: Selects all siblings that share the same parent as the specified
element.
8. Attribute Selector:
word.
9. Pseudo-classes:
: hover: Selects and styles an element when the mouse hovers over it.
10. Pseudo-elements:
Example:
p{
color: blue;
.highlight {
background-color: yellow;
#header {
font-size: 24px;
}
/* Selects the first child of each 'div' */
font-weight: bold;
tr:nth-child(odd) {
background-color: #f2f2f2;
5). Discuss the concept of BOX model in CSS with neat diagram
When laying out a document, the browser's rendering engine represents each element as a rectangular box
according to the standard CSS basic box model. CSS determines the size, position, and properties (color,
Every box is composed of four parts (or areas), defined by their respective edges: the content edge, padding
The content area, bounded by the content edge, contains the "real" content of the element, such as text, an
image, or a video player. Its dimensions are the content width (or content-box width) and the content
height (or content-box height). It often has a background color or background image.
If the box-sizing property is set to content-box (default) and if the element is a block element, the content
area's
size can be explicitly defined with the width, min-width, max-width, height, min-height, and max-
height properties.
Padding area
The padding area, bounded by the padding edge, extends the content area to include the element's padding.
Its
The thickness of the padding is determined by the padding-top, padding-right, padding-bottom, padding-left,
Border area
The border area, bounded by the border edge, extends the padding area to include the element's borders. Its
The thickness of the borders are determined by the border-width and shorthand border properties. If the box-
sizing property is set to border-box, the border area's size can be explicitly defined with the width, min-
width, max-width, height, min-height, and max-height properties. When there is a background (background-
color or background-image) set on a box, it extends to the outer edge of the border (i.e. extends underneath
the border in z-ordering). This default behavior can be altered with the background-clip CSS property.
Margin area
The margin area, bounded by the margin edge, extends the border area to include an empty area used to
separate
the element from its neighbors. Its dimensions are the margin box width and the margin box height.
The size of the margin area is determined by the margin-top, margin-right, margin-bottom, margin-left, and
shorthand margin properties. When margin collapsing occurs, the margin area is not clearly defined since
Finally, note that for non-replaced inline elements, the amount of space taken up (the contribution to the
height
of the line) is determined by the line-height property, even though the borders and padding are still displayed
Controls Statement
1. If Statement
2. If else statement
3. if else if statement
JavaScript If statement
It evaluates the content only if expression is true. The signature of JavaScript if statement is given
below.
if(expression){
//content to be evaluate
}
Let’s see the simple example of if statement in javascript.
<script>
var a=20;
if(a>10){
</script>
It evaluates the content whether condition is true of false. The syntax of JavaScript if-else statement
is given below.een
if(expression){
else{
Let’s see the example of if-else statement in JavaScript to find out the even or odd number.
<script>
var a=20;
if(a%2==0){
document.write("a is even number");
else{
</script>
a is even number
It evaluates the content only if expression is true from several expressions. The signature of
if(expression1){
else if(expression2){
else if(expression3){
else{
}
Let’s see the simple example of if else if statement in javascript.
<script>
var a=20;
if(a==10){
else if(a==15){
else if(a==20){
else{
</script>
a is equal to 20
JavaScript Switch
The JavaScript switch statement is used to execute one code from multiple expressions.
It is just like else if statement that we have learned in previous page. But it is convenient
case value1:
code to be executed;
break;
case value2:
code to be executed;
break;
......
default:
<script>
var grade='B';
var result;
switch(grade){
case 'A':
result="A Grade";
break;
case 'B':
result="B Grade";
break;
case 'C':
result="C Grade";
break;
default:
result="No Grade";
document.write(result);
</script>
B Grade
JavaScript Loops
The JavaScript loops are used to iterate the piece of code using for, while, do while or for-
1. for loop
2. while loop
3. do-while loop
The JavaScript for loop iterates the elements for the fixed number of times. It should be
used if number of iteration is known. The syntax of for loop is given below.
code to be executed
}
<script>
document.write(i + "<br/>")
</script>
Output:
The JavaScript while loop iterates the elements for the infinite number of times. It should
be used if number of iteration is not known. The syntax of while loop is given below.
while (condition)
code to be executed
var i=11;
while (i<=15)
document.write(i + "<br/>");
i++;
</script>
Output:
11
12
13
14
15
The JavaScript do while loop iterates the elements for the infinite number of times like
while loop. But, code is executed at least once whether condition is true or false. The syntax
do{
code to be executed
}while (condition);
<script>
var i=21;
do{
document.write(i + "<br/>");
i++;
}while (i<=25);
</script>
Output:
21
22
23
24
25
ARRAY
1. By array literal
var arrayname=[value1,value2.....valueN];
As you can see, values are contained inside [ ] and separated by , (comma).
Let's see the simple example of creating and using array in JavaScript.
<script>
var emp=["Sonoo","Vimal","Ratan"];
for (i=0;i<emp.length;i++){
document.write(emp[i] + "<br/>");
</script>
Sonoo
Vimal
Ratan
<script>
var i;
emp[0] = "Arun";
emp[1] = "Varun";
emp[2] = "John";
for (i=0;i<emp.length;i++){
document.write(emp[i] + "<br>");
}
</script>
Arun
Varun
John
Here, you need to create instance of array by passing arguments in constructor so that we
<script>
for (i=0;i<emp.length;i++){
document.write(emp[i] + "<br>");
</script>
Jai
Vijay
Smith.
their respective properties with other elements. These are referred to as specific
Get Element by ID
the ID property matches the desired string. Moreover, you should note that IDs should
be unique once specified in order to access the required elements. This method is
very simple and easy to find the HTML element in the DOM, as you will be able to
<!DOCTYPE html>
<html>
<body>
<p></p>
<p id=”demo”></p>
<script>
document.getElementById(“demo”).innerHTML =
</script>
</body>
</html>
From the example above, if an element is found, an object element will return in
elements with their respective tag names. So, when trying to get element by name in
• All the hierarchical orders specified will be searched except the main element.
• The live list of HTML collections keeps updating the DOM tree automatically.
• DOM can change between the calls so we just use this method once to avoid repetition.
• The arguments are lower-cased automatically when working with HTML elements.
• By using Element.getElementByTagName(), automatic lower-case can be prevented.
We should work with the following syntax when implementing this method:
elements = element.getElementsByTagName(tagName)
We will be using two examples for the Tag Name. Let’s look at the first one:
<!DOCTYPE html>
<html>
<body>
<h2>HTML DOM Element</h2>
<p></p>
<p id=”demo”></p>
<script>
‘ + element[0].innerHTML;
</script>
</body>
</html>
Looking at the example shown above, we have used a Tag Name. Now, let’s see
From the second example, we will see interaction with ID and then with the Tag
Name:
<!DOCTYPE html>
<html>
<body>
<div id=”main”>
<p>We are finding HTML Elements by Tag Name using ID</p>
<p></p>
</div>
<p id=”demo”></p>
<script>
const x = document.getElementById(“SampleID”);
const y = x.getElementsByTagName(“p”);
document.getElementById(“demo”).innerHTML =
</script>
</body>
</html>
Class Name
This object will have hierarchical elements with the respective class names. Note the
• This method will search the complete document, even the root node.
• Only the descendent elements of the specified class names will return once
getElementByClassName() is called.
• Just like Tag Name, this is a live HTML collection as well; hence, any change will be updated
automatically in the array. Thus, extra care is needed to avoid repetition.
<!DOCTYPE html>
<html>
<body>
<p class=”intro”></p>
<p id=”demo”></p>
<script>
const x = document.getElementsByClassName(“intro”);
document.getElementById(“demo”).innerHTML =
</script>
</body>
</html>
The example above would return all the elements of the “intro” class.
CSS Selectors
For CSS selectors, we will use the querySelector() method. This process brings us a
matching specified CSS selector from the document. Before implementing it yourself,
• To return other matches, we have to use the querySelectorAll() method because the querySelector()
method brings us only the first element.
• We have to be careful with using ID in our document because this methodwill return any element
that matches, even an ID.
– Parameters of QuerySelector
When working with CSS selectors, we must remember the following parameters:
matching the elements. These selectors use the JavaScript find element
the selectors in an organized manner. Still, the first element found would be
the result.
The string used with the selectors should be compatible with the CSS
For a literal string, we must escape for the JavaScript string and then for
querySelector() as well.
Make sure the ID is not used more than once as the selector can return that
element = document.querySelector(selectors);
– CSS Selector Examples
We will be seeing some examples using different practices to understand the CSS
selectors role with elements. Moreover, in the example below, we should get the
<!DOCTYPE html>
<html>
<body>
<p>We can add a background color to the first element with class.</p>
<script>
function myFunction() {
</script>
</body>
</html>
<!DOCTYPE html>
<html>
<body>
<p>This is a p element.</p>
<script>
function myFunction() {
</script>
</body>
</html>
Now, we will see an example where the first <p> element interacts with a class.
<!DOCTYPE html>
<html>
<body>
<p>We can add a background color to the first p element with class.</p>
<script>
function myFunction() {
document.querySelector(“p.example”).style.backgroundColor = “desired color”;
</script>
</body>
</html>
Let’s see how a target attribute within an <a> element works in the example as
follows:
<!DOCTYPE html>
<html>
<head>
<style>
a[target] {
</style>
</head>
<body>
<p>The CSS selector a[target] ensures the desired color becomes the background of all
the targets.</p>
<a href=”http://samplewebsitelink.com”>samplewesbite.com</a>
<script>
function myFunction() {
</script>
</body>
</html>
We mentioned multiple selectors earlier, so now it’s time that we see a first-hand
<!DOCTYPE html>
<html>
<body>
<h3>A h3 element</h3>
<h2>A h2 element</h2>
<script>
</script>
</body>
</html>
In this code block, we took two elements (h3 and h2). The code adds the desired
background color to the first element specified. We must remember that whatever
element is placed first will get the background color. From the example above, we
The last method to JavaScript find element uses forms collection to display the
<!DOCTYPE html>
<html>
<body>
</form>
<p id=”demo”></p>
<script>
const x = document.forms[“frm1”];
document.getElementById(“demo”).innerHTML = text;
</script>
</body>
</html>
Unit – 2
1).Briefly explain the concept of XML document. Declaration and vocabularies with
suitable examples.
An XML document is a basic unit of XML information composed of elements and other
markup in an orderly package. An XML document can contains wide variety of data. For
equation.
Syntax
Each parameter consists of a parameter name, an equals sign (=), and parameter value inside
a quote.
<?xml
version = "version_number"
encoding = "encoding_declaration"
standalone = "standalone_status"
?>
Rules
If the XML declaration is present in the XML, it must be placed as the first line in the
XML document.
The order of placing the parameters is important. The correct order is: version,
Versioning XML vocabularies is crucial to manage changes in the structure and semantics of
XML documents over time. Proper versioning helps ensure interoperability between systems
that exchange XML data, especially when updates or modifications are made to the XML
schema. Here are some common practices for versioning XML vocabularies:
1. Namespace Versioning:
Include a version attribute or element within the XML document to indicate its
version.
For example:
<MyVocabulary version="2.0">
</MyVocabulary>
3. Backward Compatibility:
Clearly define version information within the XML schema itself. This can be
Use tools like XML Schema Definition (XSD) or Document Type Definition
(DTD) to formally define the structure and constraints of your XML documents.
5. Documentation:
newer versions.
6. Deprecation:
Develop XML parsers that can handle multiple versions of the XML schema.
Ensure that these parsers can adapt to changes without causing errors in older
documents.
8. Version Negotiation:
Implement a mechanism for systems to negotiate and agree on the version of the
9. Semantic Versioning:
vocabularies. This convention helps convey the nature of changes (major, minor,
10.Testing:
Thoroughly test the XML schema and its compatibility with different versions.
This includes testing with real-world data and ensuring that the versioning
XML declaration
The XML declaration is a statement placed at the beginning of an XML document to provide
essential information about the document itself. It is an optional component, but when used,
2. version="1.0": Specifies the version of the XML specification to which the document
adheres. The version number is essential for parsers to interpret the document correctly.
specifies the mapping between characters and byte sequences. "UTF-8" is a widely
used encoding that supports a broad range of characters from different languages. Other
document is standalone or not. A standalone document is one that does not rely on
external entities for its complete interpretation. The value can be "yes" or "no."
The XML declaration is not required, but including it is good practice, especially when
specifying the character encoding. If the declaration is absent, XML parsers assume default
<root>
<element1>Value 1</element1>
<element2>Value 2</element2>
</root>
XML and its types
variables, etc.) scope to avoid name conflicts. For instance, a program may need to use the
same variable name in many contexts. In such a case, namespaces will separate these contexts
A namespace is not by default available in JavaScript. Constructing a global object that contains
all functions and variables, the JavaScript Namespace feature may be repeated. Because
numerous libraries and components are utilized in contemporary online applications, namespace
In the Object Literal Notation, JavaScript namespaces can only be specified once, and
With a colon between each pair of keys and values, this may be compared to an object
with a collection of key-value pairs, where keys can also stand in for new namespaces.
The benefit of object literals is that they help properly organize code and arguments while
They are quite helpful if you want to design structures that can be extended to enable
Contrary to simple global variables, object literals frequently additionally consider checks
for the presence of a variable with the same name, considerably lowering the likelihood
of a collision.
Syntax
Var <namespace> = { };
<namespace>.<identifier>
Approach
Inside the getStudentName() function we have a variable that is initialized to the name
Outside the object, we call these functions, and similarly each value is printed.
Example
</head>
<body>
<script>
var student = {
getStudentName: function() {
},
getstudentAddress: function() {
return studentAddress;
};
document.write(student.getStudentName());
document.write(student.getstudentAddress());
</script>
</body>
</html>
Output:
AJAX
AJAX is a technique for accessing web servers from a web page.
A browser built-in XMLHttpRequest object (to request data from a web server)
AJAX allows web pages to be updated asynchronously by exchanging data with a web
server behind the scenes. This means that it is possible to update parts of a web page,
<!DOCTYPE html>
<html>
<body>
<div id="demo">
</div>
</body>
</html>
An XPath expression generally defines a pattern in order to select a set of nodes. These patterns are
XPath specification specifies seven types of nodes which can be the output of execution of the
XPath expression.
Root
Element
Text
Attribute
Comment
Processing Instruction
Namespace
XPath uses a path expression to select node or a list of nodes from an XML document.
Following is the list of useful paths and expression to select any node/ list of nodes from an XML
document.
1 node-name
2/
3 //
Selection starts from the current node that match the selection
4.
Selects the current node
5 ..
6@
Selects attributes
7 Student
8 class/student
9 //student
Selects all student elements no matter where they are in the document
Example
In this example, we've created a sample XML document, students.xml and its stylesheet
document students.xsl which uses the XPath expressions under select attribute of various XSL
tags to get the values of roll no, firstname, lastname, nickname and marks of each student node.
students.xml
<class>
<firstname>Dinkar</firstname>
<lastname>Kad</lastname>
<nickname>Dinkar</nickname>
<marks>85</marks>
</student>
<firstname>Vaneet</firstname>
<lastname>Gupta</lastname>
<nickname>Vinni</nickname>
<marks>95</marks>
</student>
<firstname>Jasvir</firstname>
<lastname>Singh</lastname>
<nickname>Jazz</nickname>
<marks>90</marks>
</student>
</class>
students.xsl
xmlns:xsl = "http://www.w3.org/1999/XSL/Transform">
<html>
<body>
<h2>Students</h2>
<table border = "1">
<th>Roll No</th>
<th>First Name</th>
<th>Last Name</th>
<th>Nick Name</th>
<th>Marks</th>
</tr>
<tr>
</tr>
</xsl:for-each>
</table>
</body>
</html>
</xsl:template>
</xsl:stylesheet>
Displaying XML Using XSLT
XSLT is used to transform XML document from one form to another form.
The result of applying XSLT to XML document could be an another XML document,
The XSL code is written within the XML document with the extension of (.xsl).
XML Namespace is used to avoid the name conflicts in the XML document.
It is declared using reserved attribute such as the attribute is xmlns or it can begin
with xmlns:
Syntax:
Where
Example:
Consider the following xml document named Table.xml :-
<tables>
<table>
<tr>
<td>Apple</td>
<td>Banana</td>
</tr>
</table>
<table>
<height>100</height>
<width>150</width>
</table>
</tables>
The XMLHttpRequest object can be used to exchange data with a web server behind the
scenes. This means that it is possible to update parts of a web page, without reloading
in XMLHttpRequest object.
In this case, the callback function should contain the code to execute when the response
is ready.
xhttp.onload = function() {
Send a Request
To send a request to a server, you can use the open() and send() methods of
xhttp.open("GET", "ajax_info.txt");
xhttp.send();
Example
xhttp.onload = function() {
}
// Send a request
xhttp.open("GET", "ajax_info.txt");
xhttp.send();
Method Description
Property Description
2: request received
3: processing request
200: "OK"
403: "Forbidden"
Property Description
The responseText property returns the server response as a JavaScript string, and you
document.getElementById("demo").innerHTML = xhttp.responseText;
The responseXML Property
The responseXML property returns the server response as an XML DOM object.
Using this property you can parse the response as an XML DOM object:
Example:
const x = xmlDoc.getElementsByTagName("ARTIST");
document.getElementById("demo").innerHTML = txt;
xhttp.open("GET", "cd_catalog.xml");
xhttp.send();
Method Description
getAllResponseHeaders() Returns all the header information from the server resource
The getAllResponseHeaders() Method
The getAllResponseHeaders() method returns all header information from the server
response.
xhttp.onload = function() {
document.getElementById("demo").innerHTML =
this.getAllResponseHeaders();
xhttp.open("GET", "ajax_info.txt");
xhttp.send();
The getResponseHeader() method returns specific header information from the server
response.
xhttp.onload = function() {
document.getElementById("demo").innerHTML =
this.getResponseHeader("Last-Modified");
xhttp.open("GET", "ajax_info.txt");
xhttp.send();
UNIT -3
1).Explain the types of selectors in JQuery with an example
jQuery selectors are used to select the HTML element(s) and allows you to manipulate
the HTML element(s) in a way we want. It selects the HTML elements on a variable
parameter such as their name, classes, id, types, attributes, attribute values, etc. All
selectors in jQuery are selected using a special sign i.e. dollar sign and parentheses:
1. jQuery * Selector
The jQuery * selector selects all the elements in the document, including HTML,
body, and head. If the * selector is used together with another element then it selects
Syntax:
$("*")
Parameters:
The #id selector specifies an id for an element to be selected. It should not begin
with a number and the id attribute must be unique within a document which means it
Syntax:
$("#id")
Parameter:
Given an HTML document and the task is to select the elements with different ID’s
at the same time using JQuery.
Approach:
Select the ID’s of different element and then use each() method to apply the CSS
Then use css() method to set the background color to pink to all selected
elements.
The jQuery .class selector specifies the class for an element to be selected. It should
Syntax:
$(".class")
Parameter:
selected.
The jQuery multiple class selector is used to select multiple classes of an HTML
document.
Syntax:
Parameter:
selected.
6.jQuery element Selector
jQuery element selector is used to select and modify HTML elements based on the
element name.
Syntax:
$("element_name")
HTML document.
Syntax:
Parameter:
The jQuery :first Selector is used to select the first element of the specified type.
Syntax:
$(":first")
The jQuery :last Selector is used to select the last element of the specified type.
Syntax:
$(":last")
The jQuery:even selector used to select an even number index from the elements.
The number of the index starts from 0. The working is the same as odd selectors but
for even numbers.
Syntax
$(":even")
The jQuery :odd selector is used to select an odd number index from the elements.
The number of indexes starts from 0. The working is the same as :even selectors but
Syntax:
$(":odd")
jQuery :first-child Selector is used to select every element that is the first child of
Syntax:
$("selector:first-child")
It selects and returns the first child element of its parent element.
The jQuery :first-of-type Selector is used to select all elements that are the first
Syntax:
$(":first-of-type")
It is a jQuery Selector used to select every element that is the last child of its parent.
Syntax:
$(":last-child")
2 ).Briefly explain the AngularJS directives and expressions with suitable examples
Angularjs expressions:
AngularJS will resolve the expression, and return the result exactly where the
expression is written.
AngularJS expressions are much like JavaScript expressions: They can contain
Example
<!DOCTYPE html>
<html>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.6.9/angular.min.
js"></script>
<body>
<div ng-app="">
</div>
</body>
</html>
</div>
AngularJS numbers
</div>
</div>
AngularJS strings
</div>
</div>
AngularJS objects
</div>
</div>
AngularJS arrays
</div>
</div>
AngularJS Directives:
AngularJS facilitates you to extend HTML with new attributes. These attributes are
called directives.
Directives are special attributes starting with ng- prefix. Following are the most common
directives:
AngularJS Directives
AngularJS directives are extended HTML attributes with the prefix ng-.
The ng-model directive binds the value of HTML controls (input, select, textarea) to
application data.
The ng-repeat: This directive repeats html elements for each item in a collection.
ng-app directive
ng-app directive defines the root element. It starts an AngularJS Application and
AngularJS Application.
</div>
ng-init directive
ng-init directive initializes an AngularJS Application data. It defines the initial values for
an AngularJS application.
In following example, we'll initialize an array of countries. We're using JSON syntax to
{locale:'en-IND',name:'India'},
{locale:'en-PAK',name:'Pakistan'},
{locale:'en-AUS',name:'Australia'}]">
</div>
ng-model directive:
</div>
ng-repeat directive
ng-repeat directive repeats html elements for each item in a collection. In following
{name:'Jani',country:'Norway'},
{name:'Hege',country:'Sweden'},
{name:'Kai',country:'Denmark'}]">
<ul>
</li>
</ul>
</div>
3).Explain the different types of events available in JQuery with suitable examples
Event refers to the actions performed by the site visitor during their interactivity with
click()
The click() method contains an function for event handling which gets invoked when the user clicks on the
particular HTML element.
Syntax:
$(selector).click(function);
dblclick()
The dblclick() method contains an function for event handling which gets invoked when the user double
clicks on the particular HTML element.
Syntax:
$(selector).dblclick(args);
mouseenter()
The mouseenter() method contains an function for event handling which gets invoked when mouse pointer
enters the particular HTML element.
Syntax:
$(selector).mouseenter(function)
mouseleave()
The mouseleave() method contains an function for event handling which gets invoked when mouse pointer
is removed from the particular HTML element which was selected earlier.
Syntax:
$(selector).mouseleave(function)
mousedown()
The mousedown() method contains an function for event handling which gets invoked when mouse left,
right or middle button is pressed while the mouse pointer is over the HTML element.
Syntax:
$(selector).mousedown(function)
mouseup()
The mouseup() method contains an function for event handling which gets invoked when mouse left, right
or middle button is released while the mouse pointer is over the HTML element. hover() The hover() method
contains an function for event handling which gets invoked when mouse pointer enter and leaves the HTML
Explain the concept of bootstrap grid system with different types of classes
Bootstrap's grid system is responsive, and the columns will re-arrange depending on the
screen size: On a big screen it might look better with the content organized in three
columns, but on a small screen it would be better if the content items were stacked on top
of each other.
If you do not want to use all 12 column individually, you can group the columns together
Grid Classes
lg (for laptops and desktops - screens equal to or greater than 1200px wide)
The classes above can be combined to create more dynamic and flexible layouts.
Tip: Each class scales up, so if you wish to set the same widths for xs and sm, you only
Content should be placed within columns, and only columns may be immediate
children of rows
Predefined classes like .row and .col-sm-4 are available for quickly making grid
layouts
Columns create gutters (gaps between column content) via padding. That padding
is offset in rows for the first and last column via negative margin on .rows
Grid columns are created by specifying the number of 12 available columns you
wish to span. For example, three equal columns would use three .col-sm-4
Column widths are in percentage, so they are always fluid and sized relative to
<div class="container">
<div class="row">
<div class="col-*-*"></div>
<div class="col-*-*"></div>
</div>
<div class="row">
<div class="col-*-*"></div>
<div class="col-*-*"></div>
<div class="col-*-*"></div>
</div>
<div class="row">
...
</div>
</div>
So, to create the layout you want, create a container (<div class="container">). Next,
create a row (<div class="row">). Then, add the desired number of columns (tags with
appropriate .col-*-* classes). Note that numbers in .col-*-* should always add up to
Grid Options
The following table summarizes how the Bootstrap grid system works across multiple
devices:
We will create a basic grid system that starts out stacked on extra small devices, before
meaning it will result in a 50%/50% split on all screens, except for extra small screens,
Example: Stacked-to-horizontal
<div class="container">
<h1>Hello World!</h1>
<div class="row">
</div>
<p>Sed ut perspiciatis...</p>
</div>
</div>
</div>
Assume we have a simple layout with two columns. We want the columns to be split
Tip: Small devices are defined as having a screen width from 768 pixels to 991 pixels.
The following example will result in a 25%/75% split on small (and medium and large)
Tip: Medium devices are defined as having a screen width from 992 pixels to 1199
pixels.
Tip: Large devices are defined as having a screen width from 1200 pixels and above.
UNIT – 4
We can create and use forms in PHP. To get form data, we need to use PHP superglobals $_GET and
$_POST.
The form request may be get or post. To retrieve data from get request, we need to use $_GET, for post
request $_POST.
Get request is the default form request. The data passed through get request is visible on the URL
browser so it is not secured. You can send limited amount of data through get request.
Let's see a simple example to receive data from get request in PHP.
File: form1.html
</form>
File: welcome.php
<?php
?>
Post request is widely used to submit form that have large amount of data such as file upload, image
The data passed through post request is not visible on the URL browser so it is secured. You can send
Let's see a simple example to receive data from post request in PHP.
File: form1.html
<table>
</table>
</form>
File: login.php
<?php
Output:
The ‘include’ (or require) statement copies all of the text, code, and mark-up from the
defined file into the include statement's target file. When you want to use the
same PHP, HTML, or text on different pages of a website, including files comes in
handy.
Include in PHP helps one build various functions and elements that can be reused
through several pages. Scripting the same feature through several pages takes time
and effort. This can be avoided if we adopt and use the file inclusion principle, which
allows us to combine several files, such as text or codes, into a single program,
PHP Include helps to include files in various programs and saves the effort of writing
code multiple times. If we want to change a code, rather than editing it in all of the
files, we can simply edit the source file, and all of the codes will be updated
automatically. There are two features that assist us in incorporating files in PHP.
1. include
2. require
Include Statement
The ‘include’ or ‘require’ statement can be used to insert the content of one PHP file into
another PHP file (before the server executes it). Except in the case of failure, the ‘include’
Require will produce a fatal error (E_COMPILE_ERROR) and interrupt the script.
If the include statement appears, execution should continue and show users the output even
if the include file is missing. Otherwise, always use the required declaration to include the
main file in the flow of execution while coding Framework, CMS, or a complex PHP
program. This will help prevent the application's protection and reputation from being
The include() function copies all of the text from a given file into the file that uses the
include function. It produces an alert if there is a problem loading a file; however, the script
Code Reusability: We may reuse HTML code or PHP scripts in several PHP scripts with
Easy to Edit: If you want to alter anything on a website, you can modify the source file
used with all of the web pages rather than editing each file individually.
PHP Include
Include is a keyword to include one PHP file into another PHP file. While including
the content of the included file will be displayed in the main file. The below
Syntax:
include 'file_name';
or
require 'file_name';
Code:
Page1.php
<?php
?>
Main.php
<html>
<body>
<p>Some text.</p>
</body>
</html>
PHP Require
The PHP require function is similar to the include function, which is used to include
files. The only difference is that if the file is not found, it prevents the script from
The require() function copies all of the text from a given file into the file that uses the
include function. The require() function produces a fatal error and stops the script's
execution if there is a problem loading a file. So, apart from how they treat error
conditions, require() and include() are identical. Since scripts do not execute if files
Syntax:
require 'file_name';
Or
require ('file_name');
Code:
Menu1.html:
<html>
<body>
<ahref="http://www.google.com">Google</a> |
<ahref="http://www.yahoo.com">Yahoo</a> |
<ahref="http://www.maps.com">Maps</a> |
<ahref="http://www.tutorial.com">Tutorial</a>
</body>
</html>
Main.html:
<html>
<body>
<h1>welcome</h1>
</body>
</html>
$_GET Superglobals
In this example:
• A form asks the user for a username and submits it via the GET method to index.php.
• The form submits the data to the same page (index.php), allowing the same script to process
the data.
• The form includes a text input field for the username.
• The submit button sends the form data when clicked.
• After submission, PHP retrieves and displays the entered username using $_GET['username'].
• Since the form uses the GET method, the form data (like the username) is appended to the URL
as query parameters (e.g., index.php?username=anjali), making the username visible in the
browser’s URL bar.
What is $_POST?
The $_POST superglobal is used to collect form data sent via the POST method. Unlike GET, the POST
method sends data in the body of the HTTP request, so the data is not visible in the URL. Some of the
features of the $_POST are:
• Retrieves data sent to the server in the body of an HTTP request, typically from HTML forms
submitted using the POST method.
• Suitable for handling sensitive or large amounts of data as it's not visible in the URL.
• More secure than $_GET for handling sensitive information like passwords.
• Accessed using associative array notation, e.g., $_POST['field_name'].
Syntax:
<?php
echo $_POST['username']; // Outputs the value of the 'username' parameter submitted via POST
?>
Now, let us understand with the help of the example:
<html>
<body>
<form action="index.php" method="post">
<label>username:</label><br>
<input type="text" name="username"><br>
<input type="submit" value="Log in"><br>
</form>
</body>
</html>
<?php
echo "{$_POST["username"]} <br>" ;
?>
Output
$_POST Superglobals
In this example:
• A form asks the user for a username and submits it via the POST method to index.php.
• The form submits the data to the same page (index.php), ensuring the data is processed on the
same script.
• The form includes a text input field for the username.
• The submit button sends the form data when clicked.
• After submission, PHP retrieves and displays the entered username using $_POST['username'].
• Since the form uses the POST method, the form data is sent in the HTTP request body, not in
the URL, so the username is not visible in the URL bar.
When to Use $_GET and $_POST
Use $_GET:
• For data like search terms or filter criteria that don't need security.
• Best for short data (due to URL length limits).
• Useful when you need to share or bookmark URLs with parameters (e.g., search queries).
• Typically used for retrieving data without modifying the server (e.g., reading data from a
database).
Use $_POST:
• Sensitive information (e.g., passwords, payment details) since it is not visible in the URL.
• Suitable for forms with larger data, such as file uploads.
• Use for submitting forms that change server-side data (e.g., registration forms).
• Prevents data from being cached or stored in browser history.
$_GET vs $_POST
Both $_GET and $_POST are superglobals in PHP used to collect form data, but they differ in how and
where the data is transmitted.
$_GET $_POST
Data is visible in the URL Data is hidden in the HTTP request body
Not secure (data is visible) More secure, but still requires sanitization
UNIT -5
1.Explain the Basic workflow prepared statement of mysql and its advantages
3.Explain the difference between the MEAN STACK AND FULL STACK development