cycling jQuery_Succinctly | Page 54

})(jQuery); After operating on the newly created HTML, it is also possible to add it into the DOM using one of jQuery's manipulation methods. Below we use the appendTo() method to add the markup to the page. Sample: sample43.html Notes: Simple elements that do not contain attributes—e.g. $('
')—are created via the document.createElement DOM method, while all other cases rely on the innerHTML property. In fact, you can directly pass the jQuery function an element created with document.createElement—e.g. $(document.createElement('div')). The HTML string passed to jQuery cannot contain elements that might be considered invalid inside of a
element. The HTML string passed to the jQuery function must be well formed. You should open and close all HTML elements when passing jQuery HTML. Not doing so could result in bugs, mostly in Internet Explorer. Just to be safe, always close your HTML elements and avoid writing shortcut HTML—e.g. $(
). Grokking the index() method You can determine the index of an element in the wrapper set by passing that element to the index() method. As an example, suppose you have a wrapper set containing all the
elements in a Web page, and you would like to know the index of the last
element. 54