回答編集履歴

3

ちょうせい

2019/10/16 02:36

投稿

yambejp
yambejp

スコア114883

test CHANGED
@@ -3,6 +3,8 @@
3
3
  (jQueryっぽく修正してあります)
4
4
 
5
5
  ```javascript
6
+
7
+ <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script>
6
8
 
7
9
  <script>
8
10
 

2

chousei

2019/10/16 02:36

投稿

yambejp
yambejp

スコア114883

test CHANGED
@@ -1,6 +1,6 @@
1
1
  こんな感じの処理になります
2
2
 
3
-
3
+ (jQueryっぽく修正してあります)
4
4
 
5
5
  ```javascript
6
6
 
@@ -8,17 +8,13 @@
8
8
 
9
9
  $(function(){
10
10
 
11
- var count=0;
11
+ $($('.wrap').get(0).childNodes).filter(function(){
12
12
 
13
- $.each($('.wrap').get(0).childNodes,function(){
13
+ return $(this).get(0).nodeName=="#text" && !$(this).get(0).nodeValue.match(/^\s+$/);
14
14
 
15
- if($(this).get(0).nodeName=="#text" && !$(this).get(0).nodeValue.match(/^\s+$/)){
15
+ }).each(function(x){
16
16
 
17
- count++;
18
-
19
- $(this).wrap(`<span class="txt${count}">`);
17
+ $(this).wrap(`<span class="txt${x+1}">`);
20
-
21
- }
22
18
 
23
19
  });
24
20
 

1

chousei

2019/10/16 02:27

投稿

yambejp
yambejp

スコア114883

test CHANGED
@@ -8,11 +8,15 @@
8
8
 
9
9
  $(function(){
10
10
 
11
+ var count=0;
12
+
11
- var html=$.each($('.wrap').get(0).childNodes,function(){
13
+ $.each($('.wrap').get(0).childNodes,function(){
12
14
 
13
15
  if($(this).get(0).nodeName=="#text" && !$(this).get(0).nodeValue.match(/^\s+$/)){
14
16
 
17
+ count++;
18
+
15
- $(this).wrap('<span class="hoge">');
19
+ $(this).wrap(`<span class="txt${count}">`);
16
20
 
17
21
  }
18
22