-
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> -
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>