jQuery
Syntax
The
jQuery syntax is tailor-made for selecting HTML elements and performing some
action on the element(s).
Basic syntax
is: $(selector).action()
- A $ sign to define/access jQuery
- A (selector) to "query (or find)" HTML elements
- A jQuery action() to be performed on the element(s)
$(this).hide() - hides the
current element.
$("p").hide() - hides all
<p> elements.
$(".test").hide() - hides all
elements with class="test".
$("#test").hide() - hides the
element with id="test".
Eg:- <!DOCTYPE html>
<html>
<head>
<script
src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script>
$(document).ready(function(){
$("button").click(function(){
$("#test").hide();
});
});
</script>
</head>
<body>
<h2>This
is a heading</h2>
<p>This
is a paragraph.</p>
<p
id="test">This is another paragraph.</p>
<button>Click
me</button>
</body>
</html>
Eg:- <!DOCTYPE html>
<html>
<head>
<script
src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script>
$(document).ready(function(){
$("button").click(function(){
$(".test").hide();
});
});
</script>
</head>
<body>
<h2
class="test">This is a heading</h2>
<p
class="test">This is a paragraph.</p>
<p>This
is another paragraph.</p>
<button>Click
me</button>
</body>
</html>
https://www.youtube.com/channel/UCKLRUr6U5OFeu7FLOpQ-FSw/videos
0 comments
Post a Comment