![]() The above code pops up an alert box displaying the raw HTML markup inside the element, as follows: Here's a paragraph of text containing a link. For example, the following code selects the p (paragraph) element in the page, then calls html() to display the HTML contents of the element: To retrieve an element’s HTML contents, first select the element as a jQuery object, then call the html() method on the object. JQuery’s html() method lets you read the HTML contents of an element as a string, or replace the element’s contents with a new HTML string. val() for reading and changing form field valuesĪs you’ll see, these methods make it very easy to read or change the raw contents or value of any HTML element.text() for reading and changing the text contents of an element.html() for reading and changing the HTML contents of an element.In this tutorial you’ll learn about 3 jQuery methods designed for working directly with the contents of an element: You’ll look at adding, removing and replacing elements in a later tutorial. Often the line between working with elements and element content is blurred - for example, when you add new elements inside an existing element, you’re effectively adding to that element’s contents. For example, you can add new elements inside, around, before, or after existing elements you can replace an element with another element (or elements) and you can read or change an element’s contents. JQuery lets you work with HTML elements and element content in many different ways. In this tutorial you’ll look at how to work with the contents of an element. Now that you know how to select HTML page elements in jQuery, you can start to do useful things with those elements.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |