jquery Assignment creation element Add class belongs to HTML content (1/4)

Source: Internet
Author: User
Tags id3

1. Selector

In HTML, we can use web effects to select an HTML tag to operate, such as modifying the attributes of HTML tags, adding a class attribute, and so on. Using jquery to select an HTML tag is easier

1 Select an HTML tag through the ID attribute of the HTML

var id = jquery ("#id3");

Id.html ("hahaha");

<div id= "ID3" ></div>

The above code gets a div tag and assigns hahaha to the contents of the tag, because the tag ID equals ID3

2) by element name selection

var ids = jquery ("div");

alert (IDs);

///////////////////////

<div>aa</div>

<div>bb</div>

The above code gets an array of elements in the array that are 2 div tags

3 Select elements through the class attribute of the element

4 through the * can select all elements

5 Select elements through element child elements

For example:

jquery ("Div li"); Get the Li child element below the DIV element

jquery ("Div li:has (a)"); Gets the Li child element below the div element, and these child elements are child elements with <a> tags, such as:<div><li><a>aa</a></li><li> </li></div> only to the first Li

jquery ("Div:eq (0)"); Get the first DIV element

jquery ("Div:lt (2)" >;//Get top two div

jquery ("div:last (0)"); Get the Post div

2. Remove first space

var s = Jquery.trim ("SSS");

3. The role of window.onload = Mybegin is to execute the Mybegin function when the document is loaded, but this sentence can only be written once, and if you want to perform multiple functions, use jquery:

jquery (document). Ready (function () {});

This sentence can also be written as: jquery (function () {});

Home 1 2 3 4 last page

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.