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