Search the Blog

Sunday, August 4, 2019

JavaScript DOM API for HTML and XML

DOM stands for Document Object Model. It is an object-oriented representation of structured documents like XML and HTML.


How to set the Text content of an element that will be appear on web browser is done by DOM API Property.
    Let us see the demo-
  <p  id="paragraph_1"></p>

Now what to show in this content is depend on the requirement, So with the help of JavaScript we can do this-
    Let see the Code-
document.getElementById("paragraph_1").textContent="Programming Logic and Code"



Demo Code Complete-

Html/JSP file Code 

<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width">

  <title>www.dizsweb.com</title>

</head>
<body>
<p id="paragraph_1"></p>
</body>
</html>


Javascript File Code
document.getElementById("paragraph_1").textContent = "Programming Logic and Code";


Output-   Programming Logic and Code



JavaScript Logging HTML elements the existing DOM

For Logging a document in HTML Page-
   
   1- Console.log(document.body);
   This will display all body of the page
     
   2- console.log(document.Location)
   This will show the location of document and ip and host and path     details. 

    3- console.log(document.url)
   This will show the location of current request to server

   4- console.log(document.activeElement)
   This will show all the active element in the current page

   5- console.log(document.cookie)
   This will show all ccokie in the current page

JavaScript Console Logging Objects by programming logic and Code

Logging Objects is used for logging JSON responses from API Calls-


Console.log(
                      {   'Id':001,
                           'User Name':'Programming Logic and Code and                                  syntax',
                           'Email id':'dizsweb@gmail.com',
                           'Description':'Programming and Logic and Syntax                             of JAVA, JavaScript, MYSql,                                                             SQL Server, Servlet, JSON, REST, JDBC'
                       }
);




Console Log Place Holders-

Syntax
    var variable1="www.dizsweb.com";
    var variable2="Programming Logic And Code"

console.log("%s,%s", variable1,variable2);

Output- www.dizsweb.com, Programming Logic And Code
var varible1="JavaScipt Program Logic and Code by Dizsweb"; 
var variable2="All type Logic and Code"; 

console.log("%s,%s",varible1,variable2);



see- also- Servlet Code for request and responce



Translate