Home > Web Front-end > JS Tutorial > Analyze the two uses of after in jQuery

Analyze the two uses of after in jQuery

巴扎黑
Release: 2017-06-24 11:30:14
Original
1989 people have browsed it

Definition and usage

after() method inserts the specified content after the selected element.

Syntax

$(selector).after(content)

Parameter Description

content Required. Specifies the content to be inserted (can include HTML tags).

Use the function to insert content

Use the function to insert the specified content after the selected element.

Syntax

$(selector).after(function(index))
Copy after login

Parameter Description

function(index)

Required. Specifies a function that returns the content to be inserted.

index - Optional. Receives the index position of the selector.

Method 1:
Insert content after each p element:

The code is as follows:

$("button").click(function(){
      $("p").after("<p>Hello world!</p>");
});
Copy after login

Method 2:

The code is as follows:

$("button").click(function(){
    $("p").after(function(n){
            
return
 "<p>The p element above has index " + n + "</p>";
    });
});
Copy after login

after in function must return an html string .

The above is the detailed content of Analyze the two uses of after in jQuery. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template