1
Fork 0
mirror of git://git.sv.gnu.org/emacs.git synced 2026-01-30 12:21:25 -08:00

Add new function dom-remove-attribute

* doc/lispref/text.texi (Document Object Model): Document it.

* lisp/dom.el (dom-remove-attribute): Add new function.
This commit is contained in:
Lars Ingebrigtsen 2020-04-30 06:05:17 +02:00
parent 0a982c077e
commit 6c1b12e7d2
4 changed files with 19 additions and 0 deletions

View file

@ -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}.

View file

@ -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

View file

@ -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'."

View file

@ -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))