Q:

Using jQuery count every element (including head, body, etc.) in the document

0

Using jQuery count every element (including head, body, etc.) in the document.

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

HTML Code :

<!DOCTYPE html>
  <html>
  <head>
  <script src="https://code.jquery.com/jquery-git.js"></script>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width">
  <title>Count  every element (including head, body, etc.) in the document.</title>
  </head>
  <body>
  <div>This is division</div>
  <span>This is a span</span>
  <p>This is a Paragraph</p>
  <button id="button1">Click to see the effect</button>
</body>
  </html>

CSS Code:

button {
    display: block;
    margin: 20px 0 0 0;
    clear: both
    }  

   div, span, p {
    width: 160px;
    height: 40px;
    float: left;
    padding: 10px;
    margin: 10px;
    background-color: #B0E0E6
  }

JavaScript Code :

$('#button1').click(function(){ 

var elementCount = $( "*" ).css( "border", "3px solid blue" ).length;
$( "body" ).prepend( "<h2>" + elementCount + " elements found</h3>" );
});

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

Similar questions


need a help?


find thousands of online teachers now