
- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
JavaScript display the result of a function as HTML?
To display the result of a function as HTML, you can use −
document.getElementById().innerHTML.
Example
Following is the code −
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Document</title> </head> <link rel="stylesheet" href="//code.jquery.com/ui/1.12.1/themes/base/jquery-ui.css"> <script src="https://code.jquery.com/jquery-1.12.4.js"></script> <script src="https://code.jquery.com/ui/1.12.1/jquery-ui.js"></script> <body> <div> <input type="text"> <br> <input type="text"> <br> <input type="radio"> <br> <input type="text"> <br> <input type="radio"> <br> </div> <br> <span id='totalNumberOfTextBox'></span> </body> <script> total_number_of_check_box(); function total_number_of_check_box() { var inputObj = document.getElementsByTagName("input"), counter = 0; for (var i = 0; i < inputObj.length; i++) { if (inputObj[i].type == "text") { counter++; } } document.getElementById('totalNumberOfTextBox').innerHTML = "Total Number of text box is=" + counter; } </script> </html>
To run the above program, save the file name anyName.html(index.html). Right click on the file and select the option “Open with live server” in VS Code editor.
Output
This will produce the following output −
- Related Questions & Answers
- Display the result difference while using ceil() in JavaScript?
- JavaScript outsider function call and return the result
- How to invoke a JavaScript Function as a function?
- Update the table by calculating the sum and display the result as last column value
- Passing a function as a callback in JavaScript
- How to subtract elements of two arrays and store the result as a positive array in JavaScript?
- Display result of a table into a temp table with MySQL?
- How to invoke a JavaScript Function as a method?
- Sort a list in MySQL and display a fixed result at the end of the column?
- MySQL query to return a string as a result of IF statement?
- Display the count of duplicate records from a column in MySQL and order the result
- Display substrings of different length with a single MySQL query and combine the result
- Particular field as result in MongoDB?
- How to get the entire document HTML as a string in JavaScript?
- MongoDB projection result as an array of selected items?
Advertisements