<!DOCTYPE html>

<html>

<head>

  <style>

  body { background:yellow; }

  button { font-size:12px; margin:2px; }

  p { width:150px; border:1px red solid; height:auto }

  div { color:red; font-weight:bold; }

  </style>

  <script src="http://code.jquery.com/jquery-1.5.js"></script>

<script>

(function() {

      // Create a new copy of jQuery using sub()

      var plugin = jQuery.sub();


      // Extend that copy with the new plugin methods

      plugin.fn.extend({

        open: function() {

          return this.show();

        },

        close: function() {

          return this.hide(10000);

        }

      });


      // Add our plugin to the original jQuery

      jQuery.fn.myplugin = function() {

        this.addClass("plugin");


        // Make sure our plugin returns our special plugin version of jQuery

        return plugin( this );

      };

})();


$(document).ready(function() {

  // Call the plugin, open method now exists

  $('#main').myplugin().close();


  // Note: Calling just $("#main").open() won't work as open doesn't exist!

});


function showMain() {


       $("#main").myplugin().open();

}

  </script>

</head>

<body>

  <button id="main">Get Paragraph Height</button>

  <button id="getd">Get Document Height</button>

  <button id="getw">Get Window Height</button>

  <button id="minaopen">open Paragraph Height</button>


  <div>&nbsp;</div>

  <p>

    Sample paragraph to test height

<br/> <br/> <br/> <br/> <br/> <br/> <br/> <br/>

  </p>

<script>

    function showHeight(ele, h) {

      $("div").text("The height for the " + ele + 

                    " is " + h + "px.");

    }

    $("#getp").click(function () { 

      showHeight("paragraph", $("p").height()); 

    });

    $("#getd").click(function () { 

      showHeight("document", $(document).height()); 

    });

    $("#getw").click(function () { 

      showHeight("window", $(window).height()); 

    });

     $("#minaopen").click(function () { 

      showMain(); 

    });


</script>


</body>

</html>

+ Recent posts