diff --git a/source/clog-element.lisp b/source/clog-element.lisp index 4bebddb..8e306d8 100644 --- a/source/clog-element.lisp +++ b/source/clog-element.lisp @@ -2229,8 +2229,24 @@ Returns CLOG-ELEMENT")) (jquery-execute obj (format nil "replaceWith(~A)" (jquery new))) obj) +;;;;;;;;;;;;;;;;;;;;;;;; +;; swap-element-by-id ;; +;;;;;;;;;;;;;;;;;;;;;;;; + +(defgeneric swap-element-by-id (html-id clog-element) + (:documentation "Replace an existing element on page with HTML-ID with +CLOG-ELEMENT and set CLOG-ELEMENT to html-id. Returns CLOG-ELEMENT")) + +(defmethod swap-element-by-id (html-id (new clog-element)) + (let ((obj (attach-as-child new html-id :new-id t))) + (setf (property new "id") html-id) + (setf (slot-value new 'html-id) html-id) + (replace-element obj new) + (destroy obj) + new)) + ;;;;;;;;;;;;;;;;;;;; -;; parent-element ;; +;; Parent-element ;; ;;;;;;;;;;;;;;;;;;;; (defgeneric parent-element (clog-element) diff --git a/source/clog.lisp b/source/clog.lisp index 4f19f04..dc650a9 100644 --- a/source/clog.lisp +++ b/source/clog.lisp @@ -349,14 +349,15 @@ embedded in a native template application.)" (vertical-align generic-function) "CLOG-Element - Methods" - (add-class generic-function) - (remove-class generic-function) - (toggle-class generic-function) - (remove-from-dom generic-function) - (remove-from-clog generic-function) - (destroy generic-function) - (click generic-function) - (replace-element generic-function) + (add-class generic-function) + (remove-class generic-function) + (toggle-class generic-function) + (remove-from-dom generic-function) + (remove-from-clog generic-function) + (destroy generic-function) + (click generic-function) + (replace-element generic-function) + (swap-element-by-id generic-function) "CLOG-Element - DOM Traversal Methods" (parent-element generic-function)