Introduction of HTML/CSS/JS: Ruchi Agarwal Software Consultant Knoldus Software
Introduction of HTML/CSS/JS: Ruchi Agarwal Software Consultant Knoldus Software
Ruchi Agarwal
Software Consultant
Knoldus Software
What is HTML?
<tagname>content</tagname>
Basic HTML page structure
Example
What is CSS?
A CSS rule has two main parts: a selector, and one or more declarations:
Combining Selectors
Syntax
#selector-id { property : value ; }
Syntax
.selector-class { property : value ; }
CSS Anchors, Links and Pseudo Classes:
Below are the various ways you can use CSS to style links.
● The CSS box model is essentially a box that wraps around HTML elements, and it consists of:
margins, borders, padding, and the actual content.
● The box model allows to place a border around elements and space elements in relation to
other elements.
Example
JavaScript in <body>
<html>
<body>
<script>
document.write("<h1>This is a heading</h1>");
</script>
</body>
</html>
External JavaScripts
Scripts can also be placed in external files. External files often contain code to be used by
several different web pages.
External JavaScript files have the file extension .js.
To use an external script, point to the .js file in the "src" attribute of the <script> tag:
<html>
<body>
<script src="myScript.js"></script>
</body>
</html>
The HTML DOM (Document Object Model)
When a web page is loaded, the browser creates a Document Object Model of the page.
The HTML DOM model is constructed as a tree of Objects:
Finding HTML Elements by Id
document.getElementById("<id-name>");
document.getElementsByTagName("<tag>");
document.getElementsByName(“<name-attr>”)
document.getElementByClass(“<class-name>”)
Writing Into HTML Output
document.write("<h1>This is a heading</h1>");
document.write("<p>This is a paragraph</p>");
Reacting to Events
Validate Input
JavaScript is commonly used to validate input.
function validateForm()
{
var nameValue=document.getElementById('name');
verifyName(nameValue);
var emailValue=document.getElementById('email');
verifyEmail(emailValue);
var password=document.getElementById('password');
verifyPassword(password,8,12);
}
function verifyName(uname)
{
Features:
● HTML/DOM manipulation
● CSS manipulation
● HTML event methods
● Effects and animations
● AJAX
jQuery Syntax
Basic syntax:
$(selector).action()
Example:
$("p").hide() - hides all <p> elements.
How to use Jquery:
<head>
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script>
</head>
jQuery Selectors:
jQuery selectors allow you to select and manipulate HTML element(s).
All the different visitors actions that a web page can respond to are called events.
An event represents the precise moment when something happens.
Example: $("p").click(function(){
// action goes here!!
});
JQuery Effects:
$(selector).hide(speed,callback);
$(selector).show(speed,callback);
$(selector).toggle(speed,callback);
$(selector).fadeIn(speed,callback);
$(selector).fadeOut(speed,callback);
$(selector).fadeToggle(speed,callback);
$(selector).fadeTo(speed,callback);
jQuery Sliding Methods
$(selector).slideDown(speed,callback);
$(selector).slideUp(speed,callback);
$(selector).slideToggle(speed,callback);
$(selector).animate({params},speed,callback);
$(selector).stop(stopAll,goToEnd);
jQuery Method Chaining
$(selector).css("color","red").slideUp(2000).slideDown(2000);
$(selector).click(function(){
alert("Text: " + $(selector).text());
alert("HTML: " + $(selector).html());
alert("Value: " + $(input-selector).val());
alert($(link-selector).attr("href"));
});
jQuery - Set Content and Attributes
$(selector).click(function(){
$(selector).text("Hello world!");
$(selector).html("<b>Hello world!</b>");
$(input-selector).val("Dolly Duck");
$(link-selector).attr("href","http://www.google.com”);
});
Syntax:
$(selector).load(URL,data,callback);
Example
ajax load()
$.ajax()
$.ajax({
url: filename,
type: 'GET',
dataType: 'html',
beforeSend: function() {
$('.contentarea').html('<img src="images/loading.gif" />');
},
success: function(data, textStatus, xhr) {
$('.contentarea').html(data);
},
error: function(xhr, textStatus, errorThrown) {
$('.contentarea').html(textStatus);
}
});
jQuery - AJAX get() and post() Methods
Two commonly used methods for a request-response between a client and server are:
GET and POST.
GET is basically used for just getting (retrieving) some data from the server.
The GET method may return cached data.
POST can also be used to get some data from the server. However, the POST
method NEVER caches data, and is often used to send data along with the request.
Syntax:
$.get(URL,callback);
$.post(URL,data,callback);