Sample analysis of the relationship between JS DOM and JQuery

  • 2020-03-30 02:37:26
  • OfStack

DOM(document object model) is a general term for element objects in the browser

Everything we do with JavaScript on a web page is done through the DOM. DOM belongs to the browser, not the core of the JavaScript language specification, so if you download a JavaScript reference help document to look it up, you won't even find the well-known document.write method.

The Document Object Model (DOM) is a programming interface for HTML and XML documents. It provides a structured representation of documents that changes the content and presentation of documents. Most of all, DOM links web pages to scripts and other programming languages. Script developers can manipulate, manipulate, and create dynamic web elements through the attributes, methods, and events of document objects. Each element of a web page (an HTML tag) corresponds to an object. The word "object" is usually translated as "object" in Taiwan. The tabs on the page are nested layer by layer, and the outermost layer is < HTML> The document object model is also nested in these layers, but is often understood as the shape of a tree. The root is the window or document object, which corresponds to the outside of the outermost tag, the entire document.

Here's a quick example:
 
<script type="text/javascript"> 
var x = document.getElementById("test"); 
var xc = x.childNodes; 
var xcl = xc.length; 
for(var i=0;i<xcl;i++){ 
document.write("nodeName = " + xc[i].nodeName + "; nodeType = " + xc[i].nodeType + "<br />");} 
</script> 

Javascript can manipulate the DOM, such as an < Table> Is a DOM object that javascript can add, remove, and so on.

A lot of people see the word "Java" in both Java and JavaScript and think they're the same thing, even myself. They're two completely different things. Java, in its full name, should be a Java Applet, a small program embedded in a web page that has its own separate window to run. Java applets are precompiled, and an Applet file (.class) is opened with Notepad and cannot be read at all. Java applets are powerful and can access protocols such as HTTP, FTP, and even create viruses on your computer (there is a precedent for this). JavaScript, by contrast, has less power. JavaScript is a type of "Script" that writes code directly into an HTML document and is not compiled and executed until the browser reads it, so you can view the JavaScript source code by looking at the HTML source file. JavaScript does not have a separate run window, the browser's current window is its run window. I think the only thing they have in common is the Java programming language. JavaScript is an object - and event-driven client-side scripting language with relative security. It is also a scripting language widely used for client-side Web development, and is often used to add dynamic functionality to HTML pages, such as responding to user actions.

Here's a quick example:
 
var myVariable="outside"; 
function myFunction(){ 
var myVariable="inside"; 
alert(myVariable); 
} 
myFunction(); 
alert(myVariable); 

Jquery is a so-called javascript framework, which is really just a collection of javacript functions, packaged.

Jquery is another excellent Javascr pt framework after prototype. It's a lightweight js library (only 21k compressed), it works with CSS3, and it works with all browsers (IE 6.0+, FF1.5+, Safari 2.0+, Opera 9.0+). JQuery makes it easier for users to work with HTML documents, events, animate, and easily provide AJAX interactions for websites. Another big advantage of jQuery is that it's well-documented, its various applications are detailed, and there are many mature plug-ins to choose from. JQuery allows the user's HTML page to keep the code separate from the HTML content, which means that instead of inserting a bunch of js commands into the HTML, you just define the id.

JQuery is the most widely used javascript library. According to statistics, 46% of the world's top 1 million websites use jQuery, far more than any other library. Microsoft even has jQuery as their official library. Learning jQuery is a must for web developers. Because it gives you an understanding of the most common technologies in the industry, it sets the stage for learning more advanced libraries in the future, and it's really easy to do a lot of complex things.

Here's a quick example:
 
<script type="text/javascript" src="jquery.js"></script> 
<script type="text/javascript"> 
$(document).ready(function(){ 
$("p").click(function(){ 
$(this).hide(); 
}); 
}); 
</script> 

Related articles: