Gets the code for the element object based on the element ID in jquery1.5.1 _jquery

Source: Internet
Author: User
In jquery1.5.1 the object returned by ID is the corresponding array, no wonder that using document.getElementById ("ID name") can take a single object, use $ ("#ID名") but not, tragedy.
Copy Code code as follows:

<! DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.0 transitional//en" "Http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd ">
<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>
<body>
<table width= "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>

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.