• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Liutauras Vilda
  • Jeanne Boyarsky
  • paul wheaton
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Henry Wong
Saloon Keepers:
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Tim Moores
  • Mikalai Zaikin
Bartenders:
  • Frits Walraven

Script for replacing DOM content

 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
In the CMS system, users create pages in the content of which there are inserts with video players in addition to the text.
The structure is as follows:



For an untrained user who does not understand the layout, replacing the codes in the right places of the HTML code is difficult and not understandable.
Task: simplify the work by bringing the content to this form:



that is, in the visual editor, he sees the headline texts that he understands and the place where the video should be located:



Can you tell me which way to dig for the implementation of the plan in javascript?
Perhaps there are already some libraries, templating tools or solutions for this kind of tasks.
I.e., in fact, you need to replace the DOM content of the page from the editor with your own code when viewing such a page.
 
Bartender
Posts: 224
7
Android Python Oracle Postgres Database Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Welcome to Coderanch!

As following site demonstrates there is a HTML property named innerHTML that can be used to retrieve or set the content of some element in DOM tree.

https://www.w3schools.com/js/js_htmldom_methods.asp

In your case you would get the DOM element with id "player1" and replace its content with the code defining a video player.

 
Edward Sharapoff
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Roland Mueller wrote:Welcome to Coderanch!



Hi Roland!

That's not exactly what I meant. I know how to use innerHTML. I already have javascript code that is ready for use with innerHTML
Now I need a parser that will extract and get all the values from the structure.:


and then get the data object:

 
Roland Mueller
Bartender
Posts: 224
7
Android Python Oracle Postgres Database Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Second trial to check whether I got your point:

Parsing of HTML code has been already done by JavaScript. Instead you could retrieve the first element of given class by using  getElementsByClassName() and then loop through its children.
In my code - that's just a starting point - I just print out the HTML tagName and the text content of the element.



Example code from OP's post:



Output I see in Firefox console:


 
The moth suit and wings road is much more exciting than taxes. Or this tiny ad:
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
reply
    Bookmark Topic Watch Topic
  • New Topic