teratail header banner
teratail header banner
質問するログイン新規登録

回答編集履歴

3

ちょうせい

2019/10/16 02:36

投稿

yambejp
yambejp

スコア117887

answer CHANGED
@@ -1,6 +1,7 @@
1
1
  こんな感じの処理になります
2
2
  (jQueryっぽく修正してあります)
3
3
  ```javascript
4
+ <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script>
4
5
  <script>
5
6
  $(function(){
6
7
  $($('.wrap').get(0).childNodes).filter(function(){

2

chousei

2019/10/16 02:36

投稿

yambejp
yambejp

スコア117887

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

1

chousei

2019/10/16 02:27

投稿

yambejp
yambejp

スコア117887

answer CHANGED
@@ -3,9 +3,11 @@
3
3
  ```javascript
4
4
  <script>
5
5
  $(function(){
6
+ var count=0;
6
- var html=$.each($('.wrap').get(0).childNodes,function(){
7
+ $.each($('.wrap').get(0).childNodes,function(){
7
8
  if($(this).get(0).nodeName=="#text" && !$(this).get(0).nodeValue.match(/^\s+$/)){
9
+ count++;
8
- $(this).wrap('<span class="hoge">');
10
+ $(this).wrap(`<span class="txt${count}">`);
9
11
  }
10
12
  });
11
13
  });