Lecture 5
Lecture 5
c o m )
jQuery with HTML and CSS
LECTURE (5)
Jquery also used to manipulate html and css.
Method Description
css() Sets or returns one or more style properties for selected elements
empty() Removes all child nodes and content from selected elements
hasClass() Checks if any of the selected elements have a specified class name
innerHeight() Returns the height of an element (includes padding, but not border)
1 | P a g e If you have any query joint the facebook group also for help and online lectures and tutorials.
https://www.facebook.com/groups/pofwccteachersofficial
Lecture 5<Jquery with HTML and CSS> Prepared by Mr. Noman Tanseer (N o m a n s h 3 9 @ g m a i l . c o m )
innerWidth() Returns the width of an element (includes padding, but not border)
offset() Sets or returns the offset coordinates for selected elements (relative
to the document)
2 | P a g e If you have any query joint the facebook group also for help and online lectures and tutorials.
https://www.facebook.com/groups/pofwccteachersofficial
Lecture 5<Jquery with HTML and CSS> Prepared by Mr. Noman Tanseer (N o m a n s h 3 9 @ g m a i l . c o m )
val() Sets or returns the value attribute of the selected elements (for
form elements)
The css() method sets or returns one or more style properties for the selected elements.
Example:-
<!DOCTYPE html>
<html>
<head>
<title>Css()</title>
<script src="jquery-1.9.1.min.js"></script>
3 | P a g e If you have any query joint the facebook group also for help and online lectures and tutorials.
https://www.facebook.com/groups/pofwccteachersofficial
Lecture 5<Jquery with HTML and CSS> Prepared by Mr. Noman Tanseer (N o m a n s h 3 9 @ g m a i l . c o m )
<script>
$(document).ready(function(){
$("button").click(function(){
$("p").css("border", "5px solid #bb00ff");
$("p").css("margin", "50px");
$("p").css("padding", "20px");
$("p").css("color", "#9955cc");
$("p").css("background-color", "#99ffcc");
// set multiple properties and values
$("p").css({"width":"500px","height":"300px"});
});
});
</script>
</head>
<body>
<h2>This is a heading</h2>
<p>This is a paragraph.</p>
</body>
</html>
Use of html( ) method
The html() method sets or returns the content (innerHTML) of the selected elements.
Example:-
<!DOCTYPE html>
<html>
<head>
<title>html()</title>
<script src="jquery-1.9.1.min.js"></script>
<script>
$(document).ready(function(){
$("button").click(function(){
$("p").html("<h1>This is replaced content</h1>");
$("h2").html("<center><img src='abc.jpg' width='700px' height='300px' /></center>");
});
4 | P a g e If you have any query joint the facebook group also for help and online lectures and tutorials.
https://www.facebook.com/groups/pofwccteachersofficial
Lecture 5<Jquery with HTML and CSS> Prepared by Mr. Noman Tanseer (N o m a n s h 3 9 @ g m a i l . c o m )
});
</script>
</head>
<body>
<p>This is a paragraph.</p>
</body>
</html>
The after() method inserts specified content after the selected elements.
Example:-
<!DOCTYPE html>
<html>
<head>
<title>after</title>
<script src="jquery-1.9.1.min.js"></script>
<script type="text/Javascript">
$(document).ready(function(){
$('p').click(function(){
$(this).after("<p>This is a text after paragraph</p>");
});
});
</script>
</head>
<body>
<p>This is a paragraph</p>
</body>
</html>
7 | P a g e If you have any query joint the facebook group also for help and online lectures and tutorials.
https://www.facebook.com/groups/pofwccteachersofficial