jquery vs. JavaScript learning to get the parent-child element Implementation code _jquery

Source: Internet
Author: User
<ptml xmlns= "http://www.w3.org/1999/xhtml" > <pead> <title>jquery Learning with JavaScript (get parent-child elements) </ title> <style type= "Text/css" > c1{background-color:green;padding:20px; . c2{background-color:red;padding:20px;} . C1 Div{background-color:gray;} </style> <script type= "Text/javascript" src= "style/jquery-1.3.2.min.js" ></script> <script type = "Text/javascript" > Function fnext (obj) {//many times require no gap between elements to get to//alert (obj.nextSibling.id); Alert (obj). Next (). attr ("id");//pass this to the JQuery object} function Fprev (obj) {//alert by $ (obj) Obj.previousSibling.id); Alert (JQuery (obj). Prev (). attr ("id")); function Fparent (obj) {//alert (obj.parentNode.className); Alert (JQuery (obj). Parent (). attr ("class")); jquery (obj). Parent (). Removeclass ("C1"). AddClass ("C2") Alert (jquery (obj). Parent (). attr ("ClassName")); Gets classname as a property to fetch} function Fchild (obj) {//var childs = obj.childnodes; var childs = jQuery (obj). Children (); for (I=0;i<childs. length;i++) {alert (childs[i].id); Each traversal of//jquery} </script> </pead> <body> <div class= "C1" onclick= "Fchild (this);" > <div id= "the" "onclick=" Fnext (this); >first</div> <div id= "second" onclick= "Fprev (this);" >second</div> <div id= "third" onclick= "fparent (this);" >parent</div> </div> </body> </ptml>
[Ctrl + A All SELECT Note: If the need to introduce external JS need to refresh to perform]

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.