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>
    <div id="blueBox" class="box"></div>
    <a href="https://cnn.com">CNN</a>
    
 
    <div>
      <button id='getIdName'>Get id of Box</button>
      <button id='getUrl'>Get href of link</button>            
    </div>
  
 
    <script src="https://code.jquery.com/jquery-3.1.0.js"></script>
  </body>
</html>
 
.box {
  width: 100px;
  height: 100px;
  border: 1px solid black;
  background-color: blue;
}
button {
  margin-top: 10px;
}
 
$(() => {
  
  $("#getIdName").click(() => {
    // read id name of .box
    const idName = $(".box").attr("id")
    alert(idName)
  })
  $("#getUrl").click(() => {
    // read href of a tag
    const url = $("a").attr("href")
    alert(url)
  })
})
Output

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

Dismiss x