Code for Retrieving Element Objects Based on element ID in jquery1.5.1

Source: Internet
Author: User

In jquery1.5.1, the corresponding array is returned by the object based on the ID. getElementById ("ID name" ") can get a single object. It is a tragedy to use $ (" # ID name.
Copy codeThe Code is as follows:
<! DOCTYPE html PUBLIC "-// W3C // dtd xhtml 1.0 Transitional // EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<Html xmlns = "http://www.w3.org/1999/xhtml">
<Head>
<Title> selector test </title>
<Style type = "text/css">
. Txtobj {background-color: # 6600FF ;}
</Style>
<Script type = "text/javascript" src = "../jquery-1.5.1.min.js"> </script>
<Script language = "JavaScript" type = "text/javascript">
$ (Document). ready (
Function ()
{
$ ("Input [type = 'text']")
. Click
(
Function ()
{
This. value = $ ("# lblMsg") [0]. innerText;
}
)
. Keydown (
Function ()
{
Alert ($ ("# divTest") [0]. innerText );
Alert ($ ("# lblMsg") [0]. innerHTML );
Alert ($ ("# txtTest") [0]. value );
Return false;
}
);
}
);
</Script>
</Head>
<Body>
<Table width = "400" border = "1" cellpadding = "0" cellspacing = "0">
<Tr>
<Td> <span id = "lblMsg"> 0123456789 </span> </td>
</Tr>
<Tr>
<Td>
<Input type = "text" id = "txtTest" class = "txtobj" value = "# $ message test"/>
</Td>
</Tr>
</Table>
<Div id = "divTest"> ABCDEFGHIJKLMNOPQRSTUVWXYZ </div>
</Body>
</Html>

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.