summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--doc/lispref/text.texi3
-rw-r--r--etc/NEWS3
-rw-r--r--lisp/dom.el6
-rw-r--r--test/lisp/dom-tests.el7
4 files changed, 19 insertions, 0 deletions
diff --git a/doc/lispref/text.texi b/doc/lispref/text.texi
index 58424a4231b..9317362a70a 100644
--- a/doc/lispref/text.texi
+++ b/doc/lispref/text.texi
@@ -5161,6 +5161,9 @@ The following are functions for altering the @acronym{DOM}.
@item dom-set-attribute @var{node} @var{attribute} @var{value}
Set the @var{attribute} of the node to @var{value}.
+@item dom-remove-attribute @var{node} @var{attribute}
+Remove @var{attribute} from @var{node}.
+
@item dom-append-child @var{node} @var{child}
Append @var{child} as the last child of @var{node}.
diff --git a/etc/NEWS b/etc/NEWS
index 025d5c14a78..c4911726a85 100644
--- a/etc/NEWS
+++ b/etc/NEWS
@@ -358,6 +358,9 @@ optional argument specifying whether to follow symbolic links.
** 'parse-time-string' can now parse ISO 8601 format strings,
such as "2020-01-15T16:12:21-08:00".
++++
+** The new function 'dom-remove-attribute' has been added.
+
---
** 'make-network-process', 'make-serial-process' :coding behavior change.
Previously, passing ":coding nil" to either of these functions would
diff --git a/lisp/dom.el b/lisp/dom.el
index 34df0e9af4c..7ff9e07b729 100644
--- a/lisp/dom.el
+++ b/lisp/dom.el
@@ -67,6 +67,12 @@
(setcdr old value)
(setcar (cdr node) (nconc (cadr node) (list (cons attribute value)))))))
+(defun dom-remove-attribute (node attribute)
+ "Remove ATTRIBUTE from NODE."
+ (setq node (dom-ensure-node node))
+ (when-let ((old (assoc attribute (cadr node))))
+ (setcar (cdr node) (delq old (cadr node)))))
+
(defmacro dom-attr (node attr)
"Return the attribute ATTR from NODE.
A typical attribute is `href'."
diff --git a/test/lisp/dom-tests.el b/test/lisp/dom-tests.el
index d44851eb13b..eb15500d84c 100644
--- a/test/lisp/dom-tests.el
+++ b/test/lisp/dom-tests.el
@@ -84,6 +84,13 @@
(dom-set-attribute dom attr value)
(should (equal (dom-attr dom attr) value))))
+(ert-deftest dom-tests-remove-attribute ()
+ (let ((dom `(body ((foo . "bar") (zot . "foobar")))))
+ (should (equal (dom-attr dom 'foo) "bar"))
+ (dom-remove-attribute dom 'foo)
+ (should (equal (dom-attr dom 'foo) nil))
+ (should (equal dom '(body ((zot . "foobar")))))))
+
(ert-deftest dom-tests-attr ()
(let ((dom (dom-tests--tree)))
(should-not (dom-attr dom 'id))