Welcome to JS Bin
Load cached copy from
 
<!DOCTYPE html>
<html>
  <head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width">
    <title>JS Bin</title>
  </head>
  <body>
    <button id="readHtmlOfParagraph">Get HTML of Paragraph</button>
    
    <button id="readHtmlOfContainer">Get HTML of Container</button>
    
    <div class="container">
      <h2>Numbers</h2>
      <p class="one"><span>One</span></p>
      <p class="two"><span>Two</span></p>
      <p class="three"><span>Three</span></p>
    </div>
    
    <script src="https://code.jquery.com/jquery-2.0.3.js"></script>
  </body>
</html>
 
$(() => {
 
  $('#readHtmlOfParagraph').click(() => {
    // get html of the first matched p element
    const htmlOfParagraph = $("p").html()
    alert(htmlOfParagraph)
  })
  
  $('#readHtmlOfContainer').click(() => {
    // get html of container
    const htmlOfContainer = $(".container").html()
    alert(htmlOfContainer)
  })
})
Output

You can jump to the latest bin by adding /latest to your URL

Dismiss x