Use native JS to get CLASS objects, and js to get class

Source: Internet
Author: User

Use native JS to get CLASS objects, and js to get class

I heard it is the most commonly used .... I think of dom programming art. Well-developed 5-year UI front-end framework!

<! DOCTYPE html PUBLIC "-// W3C // dtd xhtml 1.0 Transitional // EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">  

Sometimes multiple dom classes are the same. You can do this: carefully develop a five-year UI front-end framework!

var a=getElementsClass("ca"); for(var i=0;i<a.length;i++){ (function(i){ alert(a[i]) })(i) }

 

If there are multiple identical classes, you can use them together. If you want to achieve JQ, you can directly click the class. You also need to do some complicated processing.


How does js obtain objects based on class?

Var obj = document. getElementsByTagName ("span"); // obtain all SPAN tags first.
For (var I = 0; I <obj. length; I ++)
{
If (obj [I]. className = 'A') // find the mark of class = a in the span tag.
{
Var getObj = obj [I];
Value = getObj. innerHTML; // obtain its innerHTML
}
} // It is effective and useful, but it is stupid. I have not found any other method.

How does js obtain objects based on class?

Var obj = document. getElementsByTagName ("span"); // obtain all the SPAN tags for (var I = 0; I <obj. length; I ++) {if (obj [I]. className = 'A') // find the mark of class = a in the span mark {var getObj = obj [I]; value = getObj. innerHTML; // get his innerHTML} // or use Jquery, ext, and other JS plug-ins for processing...

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.