Looking for a simple JavaScript example that updates the DOM

I am looking for a simple JavaScript example that updates the DOM.
Any suggestions?

+4
source share
5 answers

Here is a short pure-javascript example. Suppose you have a div with id "maincontent".

var newnode = document.createTextNode('Here is some text.'); document.getElementById('maincontent').appendChild(newnode); 

Of course, everything is much simpler (especially if you want to do more complex things) with jQuery.

+5
source

@Ravi

Here is a working example of your code

 <html> <head> <title>Font Detect please</title> <script src="prototype.js" type="text/javascript"></script> <script type="text/javascript"> function changeTD() { $('Myanmar3').innerHTML = 'False'; } </script> </head> <body> <table border="1"> <tr><td>Font</td><td>Installed</td></tr> <tr><td>Myanmar3</td><td id="Myanmar3">True</td></tr> </table> <a href="javascript:void(0);" onclick="changeTD();">Click Me</a> </body> </html> 

You will notice that I have added a small link that you must click to make changes. I thought it might make the search really easy.

+1
source

I believe this jQuery tutorial has an example that can help you: http://docs.jquery.com/Tutorials:Getting_Started_with_jQuery

0
source

A more specific question may give more useful results, but here is a simple pair of snippets that shows and then updates the text in the status container element.

  // give some visual cue that you're waiting
 container.appendChild (document.createTextNode ("Getting stuff from remote server ..."));

 // then later ...        
 // update request status    
 container.replaceChild (document.createTextNode ("Done."), container.firstChild);

0
source
 <html> <head> <title>Font Detect please</title> <script src="prototype.js" type="text/javascript"></script> <script type="text/javascript"> $('Myanmar3').update('False'); $('Myanmar3').innerHTML; </script> </head> <body> <table border="1"> <tr><td>Font</td><td>Installed</td></tr> <tr><td>Myanmar3</td><td id=Myanmar3>True</td></tr> </table> </body> </html> 

I have a simple code similar to the above and I'm trying to change the True result to false using Javascript using Prototype. What can i do wrong?

Edit: Received. I did not call it .: D

0
source

Source: https://habr.com/ru/post/1276547/


All Articles