回答編集履歴

1

全属性対象版追記

2019/08/06 08:51

投稿

x_x
x_x

スコア13749

test CHANGED
@@ -15,3 +15,29 @@
15
15
  ```
16
16
 
17
17
  [https://developer.mozilla.org/ja/docs/Web/JavaScript/Reference/Global_Objects/String/replace](https://developer.mozilla.org/ja/docs/Web/JavaScript/Reference/Global_Objects/String/replace)
18
+
19
+
20
+
21
+ -- 全属性対象版追記
22
+
23
+
24
+
25
+ ```jQuery
26
+
27
+ dom.find('*').each(function(_index, element) {
28
+
29
+ $.each(element.attributes, function(_index, attribute) {
30
+
31
+ element.setAttribute(attribute.name, attribute.value.replace(/bar(\d+)/, function(_m, p) {
32
+
33
+ return 'bar' + (parseInt(p, 10) + 1).toString();
34
+
35
+ }));
36
+
37
+ });
38
+
39
+ });
40
+
41
+ ```
42
+
43
+ [https://developer.mozilla.org/ja/docs/Web/API/Element/attributes](https://developer.mozilla.org/ja/docs/Web/API/Element/attributes)