jQuery in Action

70
CHAPTER 3
Bringing pages to life with jQuery
Note that setting the inner
HTML
or text of elements using these commands will
replace contents that were previously in the elements, so use these commands
carefully. If you don't want to bludgeon all of an element's previous content, a
number of other methods will leave the contents of the elements as they are but
modify their contents or surrounding elements. Let's look at them.
3.3.2 Moving and copying elements
To add content to the end of existing content, the
append()
command is available.
This function accepts a string containing an
HTML
fragment, a reference to an
existing or newly created
DOM
element, or a jQuery wrapped set of elements.
Consider the following simple case:
$('p').append('<b>some text<b>');
This statement appends the
HTML
fragment created from the passed string to
the end of the existing content of all
<p>
elements on the page.
Command syntax: text
text(content)
Sets the text content of all wrapped elements to the passed value. If the passed text con-
tains angle brackets (< and >), these characters are replaced with their equivalent HTML
entities.
Parameters
content
(String) The text content to be set into the wrapped elements. Any angle
bracket characters are escaped as HTML entities.
Returns
The wrapped set.
Command syntax: append
append(content)
Appends the passed HTML fragment or elements to the content in all matched elements.
Parameters
content
(String|Element|Object) A string, element, or wrapped set to append to the ele-
ments of the wrapped set. See the following description for details.
Returns
The wrapped set.


Другие страницы

 
Cкачать книги бесплатно без регистрации в электронном виде (pdf, chm, txt).Вы можете читать книги онлайн на нашем сайте литературного портала книг.Большая подборка учебников, пособий, интересных книг.Электронные книги на английском языке скачать бесплатно без смс.