-
odd( ) returns Array<Element>
Matches odd elements, zero-indexed.
Example:
Finds odd table rows, matching the second, fourth and so on (index 1, 3, 5 etc.).
$("tr:odd").css("background-color", "#bbbbff");HTML:
<table border="1"> <tr><td>Row with Index #0</td></tr> <tr><td>Row with Index #1</td></tr> <tr><td>Row with Index #2</td></tr> <tr><td>Row with Index #3</td></tr> </table> -
offset( ) returns Object{top,left}
Get the current offset of the first matched element relative to the viewport.
The returned object contains two <a href='Types#Integer'>Integer</a> properties, top and left. The method works only with visible elements.Example:
Access the offset of the second paragraph:
var p = $("p:last"); var offset = p.offset(); p.html( "left: " + offset.left + ", top: " + offset.top );HTML:
<p>Hello</p><p>2nd Paragraph</p>Example:
Click to see the offset.
$("*", document.body).click(function (e) { var offset = $(this).offset(); e.stopPropagation(); $("#result").text(this.tagName + " coords ( " + offset.left + ", " + offset.top + " )"); });HTML:
<div id="result">Click an element.</div> <p> This is the best way to <span>find</span> an offset. </p> <div class="abs"> </dov> -
one( String type, Object data, Function fn ) returns jQuery
Binds a handler to a particular event to be executed <i>once</i> for each matched element.
<p>The handler is executed only once for each element. Otherwise, the same rules as described in <a href='Events/bind'>bind</a>() apply. The event handler is passed an event object that you can use to prevent default behaviour. To stop both default action and event bubbling, your handler should return false.</p><p>In most cases, you can define your event handlers as anonymous functions (see first example). In cases where that is not possible, you can pass additional data as the second paramter (and the handler function as the third), see second example.</p>Example:
Tie a one-time click to each div.
var n = 0; $("div").one("click", function(){ var index = $("div").index(this); $(this).css({ borderStyle:"inset", cursor:"auto" }); $("p").text("Div at index #" + index + " clicked." + " That's " + ++n + " total clicks."); });HTML:
<div></div> <div></div> <div></div> <div></div> <div></div> <p>Click a green square...</p>Example:
To display the text of all paragraphs in an alert box the first time each of them is clicked:
$("p").one("click", function(){ alert( $(this).text() ); }); -
onlyChild( ) returns Array<Element>
Matches the only child of its parent.
If the parent has other child elements, nothing is matched.Example:
Finds the button with no siblings in each matched div and modifies look.
$("div button:only-child").text("Alone").css("border", "2px blue solid");HTML:
<div> <button>Sibling!</button> <button>Sibling!</button> </div> <div> <button>Sibling!</button> </div> <div> None </div> <div> <button>Sibling!</button> <button>Sibling!</button> <button>Sibling!</button> </div> <div> <button>Sibling!</button> </div>Result:
[ <li>Glen</li> ]