-
last( ) returns Element
Matches the last selected element.
Example:
Finds the last table row.
$("tr:last").css({backgroundColor: 'yellow', fontWeight: 'bolder'});HTML:
<table> <tr><td>First Row</td></tr> <tr><td>Middle Row</td></tr> <tr><td>Last Row</td></tr> </table> -
lastChild( ) returns Array<Element>
Matches the last child of its parent.
While <a href='Selectors/last'>:last</a> matches only a single element, this matches more then one: One for each parent.Example:
Finds the last span in each matched div and adds some css plus a hover state.
$("div span:last-child") .css({color:"red", fontSize:"80%"}) .hover(function () { $(this).addClass("solast"); }, function () { $(this).removeClass("solast"); });HTML:
<div> <span>John,</span> <span>Karl,</span> <span>Brandon,</span> <span>Sam</span> </div> <div> <span>Glen,</span> <span>Tane,</span> <span>Ralph,</span> <span>David</span> </div> -
length returns Number
The number of elements in the jQuery object.
In a The number of elements currently matched. The <a href='Core/size'>size</a> function will return the same value.Example:
Count the divs. Click to add more.
$(document.body).click(function () { $(document.body).append($("<div>")); var n = $("div").length; $("span").text("There are " + n + " divs." + "Click to add more."); }).trigger('click'); // trigger the click to startHTML:
<span></span> <div></div> - live( String type, Function fn) returns jQuery
Possible event values: click, dblclick, mousedown, mouseup, mousemove, mouseover, mouseout, keydown, keypress, keyup
Currently not supported: blur, focus, mouseenter, mouseleave, change, submitThis method works and behaves very similarly to jQuery's bind method but with one important distinction: When you bind a "live" event it will bind to all current and future elements on the page (using http://www.sitepoint.com/blogs/2008/07/23/javascript-event-delegation-is-easier-than-you-think/). For example if you bound a live click to all "li" elements on the page then added another li at a later time - that click event would continue to work for the new element (this is not the case with bind which must be re-bound on all new elements).
.live() behaves similarly to the popular [http://plugins.jquery.com/project/livequery liveQuery] plugin but with a few major differences:
* .live (currently) supports a subset of all events. Note the full list of supported/not-supported events above.
* .live doesn't support the no-event style callback that liveQuery provides. Only event handlers can be bound with .live.
* .live doesn't have a "setup" or "cleanup" step, since all events are delegated rather than bound directly to an element.To remove a live event you should use the die method.
Example:
Click a paragraph to add another. Note that live binds the click event to all paragraphs - even new ones.
$("p").live("click", function(){ $(this).after("<p>Another paragraph!</p>"); });HTML:
<p>Click me!</p>Result:
<p>Click me!</p> <p>Another paragraph!</p> -
load( String url, Map data, Callback callback ) returns jQuery
Load HTML from a remote file and inject it into the DOM.
A GET request will be performed by default - but if you pass in any extra parameters then a POST will occur.
In jQuery 1.2 you can now specify a jQuery selector in the URL. Doing so will filter the incoming HTML document, only injecting the elements that match the selector. The syntax looks something like "url #some > selector". See the examples for more information.Example:
Load a piece of the documentation sidebar navigation into a custom unordered list.
$("#links").load("/Main_Page #p-Getting-Started li");HTML:
<b>jQuery Links:</b> <ul id="links"></ul>Example:
Load the feeds.html file into the div with the ID of feeds.
$("#feeds").load("feeds.html");Result:
<div id="feeds"><b>45</b> feeds found.</div>Example:
Same as above, but will POST the additional parameters to the server and a callback that is executed when the server is finished responding.
$("#feeds").load("feeds.php", {limit: 25}, function(){ alert("The last 25 entries in the feed have been loaded"); }); -
load ( Function fn ) returns jQuery
Binds a function to the load event of each matched element.
When bound to the window element, the event fires when the user agent finishes loading all content within a document, including window, frames, objects and images. For elements, it fires when the target element and all of its content has finished loading.Example:
Run a function when the page is fully loaded including graphics.
$(window).load(function () { // run code }); -
lt( Number index ) returns Array<Element>
Matches all elements with an index below the given one.
Example:
Finds TDs less than the one with the 4th index (TD#4).
$("td:lt(4)").css("color", "red");HTML:
<table border="1"> <tr><td>TD #0</td><td>TD #1</td><td>TD #2</td></tr> <tr><td>TD #3</td><td>TD #4</td><td>TD #5</td></tr> <tr><td>TD #6</td><td>TD #7</td><td>TD #8</td></tr> </table>