Jquery1.5.1 obtain the Element Object Based on the element ID

Source: Internet
Author: User
Although I have heard of jquery for several years, it has never been used. In the past two days, it seems that jquery is not as studious as it is. 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.

View code

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

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.