0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

htmlの書き換え

Last updated at Posted at 2021-04-22

html()

  • 任意のHTML要素を取得したり意図的に要素を追加・書き換えをすることができる
  • 取得されるHTMLは要素内の全ての子孫要素までが対象

#htmlの取得

  <body>
    <h1>jquery</h1>
    <ul>
      <li>リスト1</li>
      <li>リスト2</li>
      <li>リスト3</li>
      <li>リスト4</li>
    </ul>
    <script>   
      console.log($('li:eq(2)').html()); //リスト3
    </script>
  <body>

#htmlの書き換え

  <body>
    <h1>jquery</h1>
    <ul>
      <li>リスト1</li> //<li><a href="http://google.com">google</a></li>
      <li>リスト2</li>
      <li>リスト3</li>
      <li>リスト4</li>
    </ul>
    <script>   
      $(function() {
          $('li:eq(0)').html('<a href="http://google.com">google</a>');
      }) 
    </script>
  </body>
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?