jQuery_Complete_Guide_Fixed
jQuery_Complete_Guide_Fixed
1. What is jQuery?
jQuery is a JavaScript library designed to simplify HTML DOM tree traversal and manipulation, as well as
event handling, CSS animation, and AJAX interactions. It makes web development easier and faster.
Features of jQuery:
- Simplifies JavaScript coding.
- Reduces the amount of code required for common JavaScript tasks.
- Supports cross-browser compatibility.
- Provides built-in animations and effects.
- Allows easy AJAX implementation.
Example Program:
<html>
<head>
<script src='https://code.jquery.com/jquery-3.6.0.min.js'></script>
<script>
$(document).ready(function(){
$('button').click(function(){
$('p').hide();
});
});
</script>
</head>
<body>
<p>This is a paragraph.</p>
<button>Click to Hide</button>
</body>
</html>
Example:
$('div\\.special-class').hide(); // Selects <div class='special-class'>
Example Program:
<div id='parent'>
<p id='child'>Hello</p>
</div>
<script>
$('#child').parent().css('border', '2px solid red');
</script>
Example Program:
<input type='text' id='myInput' value='Hello'>
<button id='setValue'>Change Value</button>
<script>
$('#setValue').click(function(){
$('#myInput').val('New Value');
});
</script>
Example Program:
<div id='myDiv'>Existing Content</div>
<button id='addContent'>Add</button>
<script>
$('#addContent').click(function(){
$('#myDiv').append('<p>New Content</p>');
});
</script>
Example Program:
<div id='myDiv'>Change My Color</div>
<button id='changeColor'>Change</button>
<script>
$('#changeColor').click(function(){
$('#myDiv').css('color', 'red');
});
</script>