初めて質問します。不手際等ございましたら申し訳ございません。 以下のようにtable1行目のtdの内容を二行目以降にも表示させたいのですが 何かしら短縮させる方法等ございますか? よろしくお願い致します。
該当のソースコード
$( function(){ $("table tr:first-of-type td").wrapInner('<span>'); $("table tr:first-of-type td:nth-of-type(2) span").clone().prependTo("table td:nth-of-type(2)"); $("table tr:first-of-type td:nth-of-type(3) span").clone().prependTo("table td:nth-of-type(3)"); $("table tr:first-of-type td:nth-of-type(4) span").clone().prependTo("table td:nth-of-type(4)"); $("table tr:first-of-type td:nth-of-type(5) span").clone().prependTo("table td:nth-of-type(5)"); $("table tr:first-of-type td:nth-of-type(6) span").clone().prependTo("table td:nth-of-type(6)"); $("table tr:first-of-type td:nth-of-type(7) span").clone().prependTo("table td:nth-of-type(7)"); $("table tr:first-of-type td:nth-of-type(8) span").clone().prependTo("table td:nth-of-type(8)"); $("table tr:first-of-type td:nth-of-type(9) span").clone().prependTo("table td:nth-of-type(9)"); }); <table> <tr> <td><span>プラン</span></td> <td><span>データ容量</span></td> <td><span>バージョン情報</span></td> <td><span>料金</span></td> </tr> <tr> <td>無料プラン</td> <td> 5GB </td> <td> なし </td> <td> 無料 </td> </tr> <tr> <td> 個人事業主プラン </td> <td> 30GB </td> <td>1ヶ月まで </td> <td> 1000円/月 </td> </tr> <tr> <td> 法人プラン </td> <td> 100GB </td> <td> 無制限 </td> <td> 5000円/月 </td> </tr> </tbody> </table> ↓↓↓↓↓↓↓↓ <table> <tr> <td><span>プラン</span></td> <td><span>データ容量</span></td> <td><span>バージョン情報</span></td> <td><span>料金</span></td> </tr> <tr> <td><span>プラン</span>無料プラン</td> <td><span>データ容量</span> 5GB </td> <td> <span>バージョン情報</span>なし </td> <td> <span>料金</span>無料 </td> </tr> <tr> <td><span>プラン</span>個人事業主プラン </td> <td><span>データ容量</span> 30GB </td> <td><span>バージョン情報</span>1ヶ月まで </td> <td> <span>料金</span>1000円/月 </td> </tr> <tr> <td><span>プラン</span>法人プラン </td> <td><span>データ容量</span> 100GB </td> <td><span>バージョン情報</span>無制限 </td> <td> <span>料金</span>5000円/月 </td> </tr> </tbody> </table>
「二行目以降」というのは、html側で用意してある特定のtableの2行目から最後の行まで、ということでしょうか?
どういうHTML(table)からどういう結果を導きたいのか書いてもらったほうが早いかも
説明が足らず申し訳ございません。
以下の様なテーブルを先程のコードを利用し
<table>
  <tr>
    <td><span>プラン</span></td>
    <td><span>データ容量</span></td>
    <td><span>バージョン情報</span></td>
    <td><span>料金</span></td>
  </tr>
  <tr>
    <td>無料プラン</td>
    <td> 5GB </td>
    <td> なし </td>
    <td> 無料 </td>
  </tr>
  <tr>
    <td> 個人事業主プラン </td>
    <td> 30GB </td>
    <td>1ヶ月まで </td>
    <td> 1000円/月 </td>
  </tr>
  <tr>
    <td> 法人プラン </td>
    <td> 100GB </td>
    <td> 無制限 </td>
    <td> 5000円/月 </td>
  </tr>
  </tbody>
</table>
↓↓↓↓↓↓↓↓
<table>
  <tr>
    <td><span>プラン</span></td>
    <td><span>データ容量</span></td>
    <td><span>バージョン情報</span></td>
    <td><span>料金</span></td>
  </tr>
  <tr>
    <td><span>プラン</span>無料プラン</td>
    <td><span>データ容量</span> 5GB </td>
    <td> <span>バージョン情報</span>なし </td>
    <td> <span>料金</span>無料 </td>
  </tr>
  <tr>
    <td><span>プラン</span>個人事業主プラン </td>
    <td><span>データ容量</span> 30GB </td>
    <td><span>バージョン情報</span>1ヶ月まで </td>
    <td> <span>料金</span>1000円/月 </td>
  </tr>
  <tr>
    <td><span>プラン</span>法人プラン </td>
    <td><span>データ容量</span> 100GB </td>
    <td><span>バージョン情報</span>無制限 </td>
    <td> <span>料金</span>5000円/月 </td>
  </tr>
  </tbody>
</table>
このように変更したいと考えております。
質問文に追記してください
申し訳ございません!追記しました!
jqueryでspanをwrapInnerしてますけどソースのtr:first-of-typeにははじめからspanが入ってるんですか?
回答1件
あなたの回答
tips
プレビュー