Wikipedia:User scripts/Guide: Difference between revisions

Content deleted Content added
CSS files: Update importStylesheetURI call
Finding elements: Updated example to use jQuery
Line 167:
<source lang="html4strict">
<form name="frmname" id="frmid">
<textarea name="txtname" id="txtid"></textarea>
<input id="neighbor" />
</form>
</source>
 
we can «find» element <tt>textarea</tt>:
* using its <tt>id</tt>: <ttcode>document.'''getElementById'''$( '#txtid' )</ttcode>
* in the array of all elements with the same <tt>tag</tt>: <tt style="white-space:nowrap"code>document.'''getElementsByTagName'''$( 'textarea' )[0]</ttcode>
* using element next to it: <tt style="white-space:nowrap"code>document.getElementById$( '#neighbor').'''previousSibling'''prev()</ttcode>
* as a child of its parent: <tt style="white-space:nowrap"code>document.getElementById$( '#frmid' ).children( 'form''childNodes'''[0] )</ttcode>
* as a form element, using <tt>name</tt>: <ttcode>$( style'#frmid [name="white-space:nowraptxtname">document.'''frmname.txtname'']')</ttcode>
 
'' [http://jsfiddle.net/compwhizii/j2QRf/ This example on jsFiddle]
Also see [http://www.w3schools.com/dom/dom_element.asp w3schools] or [http://developer.mozilla.org/en/docs/DOM:element mozilla.org].
 
The [http://docs.jquery.com/Main_Page jQuery documentation] and [http://api.jquery.com jQuery API reference] are excellent sources for documentation.
<!--To see all the elements on the page and their relations simply look at the page source code.-->