Selector Extensions - E-Commerce - Lecture Slides, Slides of Fundamentals of E-Commerce

E-Commerce is taking over the traditional commerce practices. It is of special concern for the IT students. Following are the key points of these Lecture Slides : Selector Extensions, Javascript, Library, Animation, Referencing Page, Javascript Extensions, Libraries, Script Statement, Custom Mechanism, Document Complete

Typology: Slides

2012/2013

Uploaded on 07/30/2013

asif.ali
asif.ali 🇮🇳

5

(3)

129 documents

1 / 10

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
1
JQUERY,
PART 1
jQuery
What is it?
JavaScript library with DOM-like and BOM-like
functions.
Offers effects (visual, animation)
Using
Download (or link to external) jQuery script.
http://jquery.com/
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.3/jquery.min.js"
type="text/javascript"></script>
Docsity.com
pf3
pf4
pf5
pf8
pf9
pfa

Partial preview of the text

Download Selector Extensions - E-Commerce - Lecture Slides and more Slides Fundamentals of E-Commerce in PDF only on Docsity!

1

JQUERY,

PART 1

jQuery

What is it?

JavaScript library with DOM-like and BOM-like functions. Offers effects (visual, animation)

Using

Download (or link to external) jQuery script. http://jquery.com/

2

Within jQuery the $ is used as a factory function for

creating and referencing page elements.

$ is frequently used in JavaScript extensions. To

avoid name collision:

Load the other libraries first in your code. Load jQuery. Execute the script statement “jQuery.noConflict()” In lieu of $() use jQuery() in jQuery-related code.

Running jQuery code

jQuery provides a custom mechanism for running

code upon document complete load :

$(document).ready(function() {

place code here

The above illustrates a common jQuery design pattern—use of an anonymous callback function as a parameter. Watch symbol ordering at end of sequence!

4

jQuery selector extensions to CSS

jQuery defines several custom extensions that can

be used as selectors:

http://docs.jquery.com/Selectors

http://einstein.etsu.edu/~pittares/CSCI3110/examples/11-1.htm

Iteration is automatic

http://einstein.etsu.edu/~pittares/CSCI3110/examples/11-2.htm

jQuery event handling

Attach a function to events: blur, change, click,

focus, mouseover, etc.

$(selector). click (function() { function body here });

Within an event handling function $(this) references

the element the action occurred with.

http://einstein.etsu.edu/~pittares/CSCI3110/examples/11-3.htm

Function effect not removed when event concludes:

http://einstein.etsu.edu/~pittares/CSCI3110/examples/11-3a.htm

5

Toggle

toggle: takes in 2 functions and does function 1 on first click, function 2 on second click, then back to function 1, etc. $('hh').toggle(function() { function body here }, function() { function body here }); http://einstein.etsu.edu/~pittares/CSCI3110/examples/11-4.htm hover: same pattern, just change function name http://einstein.etsu.edu/~pittares/CSCI3110/examples/11-4a.htm

toggleClass

Adds and removes classes alternately with event. (If

class present, removes; if not present, adds.)

http://einstein.etsu.edu/~pittares/CSCI3110/examples/11-5.htm

http://einstein.etsu.edu/~pittares/CSCI3110/examples/11-6.htm

7

Manipulating elements

So far we’ve seen addClass(), removeClass(),

toggleClass(), and css(). There also exists:

$(selector).attr(“attribute”)—retrieves the attribute value from selector $(selector).attr(“attribute”, “value”); $(selector).attr({“attribute”: “value”, “attr”: “val”…}); --sets attribute/value pairs on selector http://einstein.etsu.edu/~pittares/CSCI3110/examples/11-10.htm

Controlling “event bubbling”

If we have an event that could be handled by more

than 1 specific event handler, the progression will

be from the more specific to the more general.

To stop event bubbling, capture the event in the

handling function and use event.stopPropagation()

$(sel).click(function( event ) { other code here; event .stopPropagation(); }); http://einstein.etsu.edu/~pittares/CSCI3110/examples/11-11.htm

8

Another use of $

$(“

This is a new paragraph

”) When HTML code is placed within $, that element is created automatically. The item is not automatically added to the page. To add, use $(‘elem’).insertBefore(sel) $(‘elem’).insertAfter(sel), $(‘sel’).append(‘elem’) $(‘sel’).prepend(‘elem’) http://einstein.etsu.edu/~pittares/CSCI3110/examples/11-12.htm

Summary

$(sel)—to choose parts of a document.

Don’t forget # if an ID!

$(html)—to create a new document element

Event handling: $(sel).eventType(function() { });

$(sel).eventType(function(event) { }); $(this) event.stopPropagation();

10

Creating new page elements

$(html) $(‘elem’).insertBefore(sel) $(‘elem’).insertAfter(sel), $(‘sel’).append(‘elem’) $(‘sel’).prepend(‘elem’)