A few examples of jquery's operations on p-Tags

Source: Internet
Author: User

This article we share several examples of using the jquery action P tag, which includes the method of getting the element itself (object) based on the ID, and jquery adding the OnClick method to each P tag, and how to add dynamic text content to the dynamically generated P tag for jquery?



Note: The following code is tested online through W3school.

Gets the elements themselves (object objects) by ID:

$ ("#id");

For example:

<! DOCTYPE html>



jquery adds the OnClick method for each P tag

<script src= ". /..  /scripts/jquery-1.3.1.js "type=" Text/javascript "></script>
<script type=" Text/javascript ">  
$ (function () {
$ ("P"). Click (function () {
alert ("I was clicked on");  
});  
});
</script>



How do I add dynamic text content to the P tag that is dynamically generated by jquery?

Reply:

$ ("<p/>"). Appendto ("Body"). HTML ("This is the content of the P tag");


The code above means appending a P tag to the body tail, and the HTML content of the P tag is this is the contents of the P tag

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.