jquery Learning-jquery Select child elements and number/get CSS Properties

Source: Internet
Author: User
Tags polyline

    • Selector Selector
    • Select child element and CSS Properties
    • Get the number of child elements

Selector Selector

The jquery selector is very powerful, so it's really handy when you can use jquery.

Select child element and CSS Properties

Let's look at the following code:

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

This code is easy to understand. First of all:

Colorid = $ ("#id");
SVG is the label of a child element.
Rect is a sub-element under SVG
Fill is a CSS property of rect

You can see that I used two children because jquery can only select one layer of child elements at a time, not the more hierarchical.

Get the number of child elements

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

<div class="box" id="C0" onclick="ChangeColor (' C0 ', ' #fe0000 ') ">                <svg width=" +" height=" viewPort" =  "0 0" version="1.1" xmlns="Http://www.w3.org/2000/svg" >             <rect x="6" y="6" width=" height " = "A" style="fill: #fe0000;" ></rect>        <polyline Fill="None" stroke= "Black" class=" Polylinehide " style=" Stroke-width:2 " points=" 2,16 2,30 16,30 "/> </polyline>        <polyline Fill="None" stroke= "Black" class=" Polylinehide " style=" Stroke-width:2 " points=" 16,2 30,2 30,16 "/> </polyline>    </svg></div>

This is an example of the HTML code. We want to get id = c0 the number of the following polyline: (should be 2) the code is as follows:

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

This is the number of fetches.

jquery Learning-jquery Select child elements and number/get CSS Properties

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.