JQuery support

<< Click to Display Table of Contents >>

Navigation:  Using script in HTML document >

JQuery support

Subset of JQuery functionality is supported via $() function when script is executed inside HTML Document.

Syntax:

$(Selector, [Context]).Operation

 

Selector is any valid CSS selector, for example

 

$('#id') - elements with id="id".

$('.myclass') - elements having CSS class myclass.

$('div') - all div elemets.

 

Context is optional context element. If context is passed, JQuery will start searching from this element.

Result is list of found elements. Operation is executed on each element in the list.

Some of operations returns element list to allow chaining.

 

Following operations are available:

 
property Attr[Name] 

  Get or set elements attribute value. When list contains several elements result is list of attribute values separated by comma.

 
property HTML: string        

  Get (for first element) or set inner HTML.

 
property CSS[name: string

  Add CSS value.

 
function Each(Proc: procedure(Element): THtNodeList

 Execute procedure Proc on each element.

 
function AddClass(ClassName: string): THtNodeList 

 Add CSS class

 
function RemoveClass(ClassName: string): THtNodeList 

 Remove CSS class

 
function ToggleClass(ClassName: string): THtNodeList 

 Toggle CSS class

 
function On(EventName: string; Code: string): THtNodeList

 Set event handler for event EventName

 
function First: THtNodeList 

 return list containing first element only

 
function Last: THtNodeList 

 return list containing last element only

 
function Parent: THtNodeList  

 return list containing parent elements of all elements

 

function Children: THtNodeList;

 return list containing chilren of all elements

 
procedure Sort(Compare: function(E1, E2: TElement), Asc: boolean) 

  sort list using Compare function

 

Example

 

Make rows of table #table selectable (user can click on row to select or deselect it)

 

$('#table tbody tr').On('click', 'this.ToggleClass(''selected'')');