Add jQuery to ASP.net

Quick Background:

I don’t know much about jQuery other than it’s a library of Javascript functions.  I wasn’t sure of how to add it to an ASP.net website running on IIS.  It’s a lot simpler than you’d think but there wasn’t a good explanation out there.

 

Quick Example:

Add…

<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script>

That links the library so that later on the page you can call jQuery.  For example this…

<script type="text/javascript">
    $(document).ready(function () {
        $("a").click(function (event) {
            alert("Thanks for visiting!");
        });
    });       
</script>

Will change all links on the page.  Instead of linking they will create a popup saying “Thanks for Visiting”.

 

Summary:

Adding jQuery to an ASP.net page is the same as adding it to any html/php/etc… page.  While you may download the javascripts I suggest using Google’s repository as it will likely load faster than hosting your own.

You can also change the version by changing the number.  The above version is 1.7.1 but you can use any versions out there.

Leave a Reply

Your email address will not be published. Required fields are marked *


+ seven = 9

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>