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="readAll">Read a paragraphs</button>
    
     <button id="readFirst">Read 1st paragraph</button>
    
    <p class="one">One</p>
    <p class="two">Two</p>
    <p class="three">Three</p>
    
    
    <script src="https://code.jquery.com/jquery-2.0.3.js"></script>
  </body>
</html>
 
$(() => {
 
  $('#readAll').click(() => {
    // read text from all p elements
    const allParagraphs = $("p").text()
    alert(`text from all paragraphs: ${allParagraphs}`)
  })
  
  $('#readFirst').click(() => {
    // read text from only the 1st p element 
    const firstParagraph = $("p:first").text()
    alert(`text from the 1st paragraph: ${firstParagraph}`)
  })
 
})
Output

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

Dismiss x