Why we use jQuery

jQuery is easy to learn as well as very simple to use. It is a JavaScript Library

It is browser independent. All browser support jQuery

It makes your application dynamic at client side.

It works with Ajax. It is not replacement of Ajax or JaveScript

jQuery is a very fast and small. It save dozens of lines of code

In below example demonstrate how get selected radio button value using jQuery as well as JavaScript. You have seen in this example we have to wright for loop to get value in JavaScript whereas we write a single line of code to get value in jQuery.

<!DOCTYPE html>
  <title>jQuery With Example</title>
  <script src="http://code.jquery.com/jquery-1.9.1.js" type="text/javascript"></script>
  <script type="text/javascript">
    $(function () {
      $('.btnJQuery').click(function (event) {
        var result = $('.gender:checked').val();
        alert(result); ;

  <script type="text/javascript">
    function getGender() {
      var result = "";
      var elements = document.getElementsByTagName('input');
      for (var n = 0; n < elements.length; n++) {
        if (elements[n].type == 'radio' && elements[n].name == 'gender' && elements[n].checked) {
          result = elements[n].value;
    <input type="radio" name="gender" class="gender" value="M" /> Male<br />
    <input type="radio" name="gender" class="gender" value="F" /> Female<br /><br />
    <input type="button" class="btnJQuery" value="jQuery Button" />
    <input type="button" class="btnJavaScript" value="JavaScript Button"  onClick="getGender()" />

No comments :

Please Give Your Feedback