1 / 11

CIS 461 Web Development I

CIS 461 Web Development I. JQuery Part I Jongwook Woo, PhD jwoo5@calstatela.edu California State University, Los Angeles Computer Information System Department. Content. jQuery HOME jQuery Intro jQuery Syntax jQuery Selectors. What is jQuery?.

zed
Download Presentation

CIS 461 Web Development I

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. CIS 461 Web Development I JQueryPart I Jongwook Woo, PhD jwoo5@calstatela.edu California State University, Los Angeles Computer Information System Department

  2. Content • jQuery HOME • jQuery Intro • jQuery Syntax • jQuerySelectors

  3. What is jQuery? • jQuery is a library of JavaScript Functions. • a lightweight "write less, do more" JavaScript library. • The jQuery library contains the following features: • HTML element selections • HTML element manipulation • CSS manipulation • HTML event functions • JavaScript Effects and animations • HTML DOM traversal and modification • AJAX • Utilities

  4. jQuery Example Adding the jQuery Library to Your Pages stored as a single JavaScript file, containing all the jQuery methods. It can be added to a web page with the following mark-up: <head><script type="text/javascript" src="jquery.js"></script></head>Please note that the <script> tag should be inside the page's <head> section. Basic jQuery Example The following example: the jQuery hide() method, hiding all <p> elements in an HTML document.

  5. jQuery Example (Cont’d) <html><head><script type="text/javascript" src="jquery.js"></script><script type="text/javascript">$(document).ready(function(){  $("button").click(function(){    $("p").hide();  });});</script></head><body> <h2>This is a heading</h2> <p>This is a paragraph.</p> <p>This is another paragraph.</p> <button>Click me</button></body></html>

  6. jQuery Download Two versions of jQuery are available for downloading: one minified and one uncompressed (for debugging or reading). Both versions can be downloaded from jQuery.com. Alternatives (hosted jQuery lib) to Downloading Google <head><script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"></script></head> Microsoft <head><script type="text/javascript" src="http://ajax.microsoft.com/ajax/jquery/jquery-1.4.2.min.js"></script></head>

  7. jQuery Syntax Basic syntax is: $(selector).action() A dollar sign to define jQuery A (selector) to "query (or find)" HTML elements A jQuery action() to be performed on the element(s) Examples: $(this).hide() - hides current element $("p").hide() - hides all paragraphs $("p.test").hide() - hides all paragraphs with class="test" $("#test").hide() - hides the element with id="test"

  8. Selectors jQuery Element Selectors uses CSS selectors to select HTML elements. $("p") selects all <p> elements. $("p.intro") selects all <p> elements with class="intro". $("p#demo") selects all <p> elements with id="demo". jQuery Attribute Selectors uses XPath expressions to select elements with given attributes. $("[href]") select all elements with an href attribute. $("[href='#']") select all elements with an href value equal to "#". $("[href!='#']") select all elements with an href attribute NOT equal to "#". $("[href$='.jpg']") select all elements with an href attribute that ends with ".jpg".

  9. Selectors (Cont’d) jQuery CSS Selectors used to change CSS properties for HTML elements. The following changes the background-color of all p elements to yellow: $("p").css("background-color","yellow");

  10. Selectors More Examples

  11. The Document Ready Function prevent any jQuery code from running before the document is finished loading (is ready). $(document).ready(function(){// jQuery functions go here...}); some examples of actions that can fail if functions are run before the document is fully loaded: Trying to hide an element that doesn't exist Trying to get the size of an image that is not loaded

More Related