Web Technologies Unit 3 Part 1
Web Technologies Unit 3 Part 1
<body>
<div>
<em title = "Bold and Brave">This is first
paragraph.</em>
<p id = "myid">This is second paragraph.</p>
<div id = "divid"></div>
</div>
</body>
</html>
jQuery <!DOCTYPE html>
<!DOCTYPE html> <html>
<html> <head>
<head> <script
<script
src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jq
src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquer
uery.min.js"></script>
y.min.js"></script>
<script> <script>
$(document).ready(function() { $(document).ready(function() {
$("em").addClass("selected"); $("#myimg").attr("src", "java.jpg");
$("#myid").addClass("highlight"); });
}); </script>
</script> </head>
<style> <body>
.selected { color:red; } <div>
.highlight { background:blue; } <img id = "myimg" src = "java.jpg" alt = "Sample
</style> image" />
</head> </div>
</body>
<body>
<em title = "Bold and Brave">This is first paragraph.</em> </html>
<p id = "myid">This is second paragraph.</p>
</body>
</html>
jQuery <!DOCTYPE html>
<html>
jQuery is a very powerful tool which provides a variety of <head>
DOM traversal methods to help us select elements in a <script
document randomly as well as in sequential method. src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.mi
n.js"></script>
<script>
Most of the DOM Traversal Methods do not modify the $(document).ready(function() {
jQuery object and they are used to filter out elements $("li").filter(".middle").addClass("selected");
from a document based on given conditions. });
</script>
filter( selector ) method can be used to filter out all <style>
elements from the set of matched elements that do not .selected { color:red; }
match the specified selector(s). </style>
</head>
<body>
find( selector ) method can be used to locate all the <div>
descendant elements of a particular type of elements <ul>
<li class = "top">list item 1</li>
add( selector ) Adds more elements, matched by the <li class = "top">list item 2</li>
given selector, to the set of matched elements. <li class = "middle">list item 3</li>
<li class = "middle">list item 4</li>
<li class = "bottom">list item 5</li>
<li class = "bottom">list item 6</li>
</ul>
</div>
</body>
</html>
jQuery <!DOCTYPE html>
<html> <head>
JQuery provides methods such as .attr(), .html(), and .val() <script
which act as getters, retrieving information from DOM src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.mi
elements n.js"></script>
<script>
$(document).ready(function() {
html( ) method gets the html contents (innerHTML) of the $("div").click(function () {
first matched element. var content = $(this).html();
.text( val ) method sets value of the object using passed $("#result").text( content );
parameter });
});
empty( ) method remove all child nodes from the set of </script>
matched elements where as the method <style>
remove( expr ) method removes all matched elements #division{ margin:10px;padding:12px; border:2px solid #666;
width:60px;}
from the DOM. </style>
</head>
after( content ) method insert content after each of the <body>
matched elements where as the method <p>Click on the square below:</p>
before( content ) method inserts content before each of <span id = "result"> </span>
the matched elements. <div id = "division" style = "background-color:green;">
This is Square!!
</div>
</body>
</html>
jQuery <!DOCTYPE html>
<html>
Ability to create dynamic web pages by using events. <head>
Events are actions that can be detected by your Web <script
Application. src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.mi
n.js"></script>
Eg., events − <script>
$(document).ready(function() {
A mouse click, A web page loading, Taking mouse over an $('div').bind('click', function( event ){
element, Submitting an HTML form, A keystroke on your alert('Welcome to Jquery!');
keyboard, etc. });
});
selector.bind( eventType[, eventData], handler)
</script>
<style>
.div{ margin:10px;padding:12px; border:2px solid #666;
hover( over, out ) width:60px;}
</style>
ready( fn )
</head>
<body>
<p>Click on any square below to see the result:</p>