Jquery learning-jquery selects child elements and numbers/gets css attributes

Source: Internet
Author: User
Tags polyline

Jquery learning-jquery selects child elements and numbers/gets css attributes

Select the child element and css attribute to obtain the number of child elements.

Selector

Jquery's selector is very powerful. If you can, it is very convenient to use jquery.

Select child element and css attribute

Let's take a look at the following code:

SelectColor = $(ColorId).children('svg').children('rect').css('fill');

This code is easy to understand. First:

ColorId = $ ("# id ");
Svg is a sub-element label.
Rect is a child element under svg.
Fill is a css attribute of rect.

We can see that I used two children, because jquery can only select one layer of child elements at a time and cannot be more hierarchical.

Obtain the number of child elements

In fact, this is also very simple.
For example, we have the following code:

 
       

This is the html code of the example. We want to obtainid = c0(It should be 2) the code is as follows:

var polyNum = $('#co').children('svg').children('polyline');alert(polyNum.length);

This is the number.

Related Article

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.