Use JavaScript to directly implement jquery's $ (". class1") Method

Source: Internet
Author: User

<HTML xmlns = "http://www.w3.org/1999/xhtml"> <br/> <pead> <br/> <title> jquery $ (". class1 ") method </title> <br/> <MCE: Script Type =" text/JavaScript "src =" style/jquery. min. JS "mce_src =" style/jquery. min. JS "> </MCE: SCRIPT> <br/> <MCE: Script Type =" text/JavaScript "> <! -- <Br/> // use JavaScript to directly implement jquery $ (". class1 ") method <br/> // the idea is to first find similar labels, such as Div and table, and then traverse the array to determine <br/> // Div label traversal is implemented here, perform table and body operations in sequence. <br/> function fcheck () {<br/> var classarray = []; // array used to save the same elements of the class <br/> var divarr = document. getelementsbytagname ("Div"); // obtain similar tags Based on the tag name <br/> for (VAR I = 0; I <divarr. length; I ++) {// traverse similar labels <br/> var divattr = divarr [I]. classname; // judge the class name <br/> If (divattr! = "") {// If there is no class attribute, It is null <br/> If (divattr = "class1") {// if similar match, put it in the array <br/> classarray. push (divarr [I]); <br/>}< br/> for (VAR J = 0; j <classarray. length; j ++) {<br/> alert (classarray [J]. innerhtml); <br/>}</P> <p> // --> </MCE: SCRIPT> <br/> </pead> <br/> <body> <br/> <Div id = "div1" onclick = "fcheck (); "> click <br/> <Div class =" class1 "> 1 </div> <br/> <Div class =" class1 "> 2 </div> <br/> <Div class = "class1"> 3 </div> <br/> </body> <br/> </ptml>

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.