Esempio n. 1
0
        /// <summary>
        /// Replace each element in the set of matched elements with the provided new content.
        /// </summary>
        ///
        /// <param name="content">
        /// The HTML string of the content to insert.
        /// </param>
        ///
        /// <returns>
        /// The current CQ object
        /// </returns>
        ///
        /// <url>
        /// http://api.jquery.com/replaceWith/
        /// </url>

        public CQ ReplaceWith(params string[] content)
        {
            if (Length > 0)
            {
                // Before allows adding of new content to an empty selector. To ensure consistency with jQuery
                // implentation, do not do this if called on an empty selector.

                // The logic here is tricky because we can do a replace on disconnected selection sets. This has to
                // track what was orignally scheduled for removal in case the set changes in "Before" b/c it's disconnected.

                CQ newContent = EnsureCsQuery(MergeContent(content));
                CQ replacing  = NewInstance(this);

                Before(newContent);
                SelectionSet.ExceptWith(replacing);
                replacing.Remove();
            }
            return(this);
        }