1

How to take a text from a div and cut the information that I don't need?

Example: I take a information about a time from a web server on a PLC, and this server returns this #T15_05 where it has minutes and seconds, is that a way to create a function to cut and transform this time for something like this 15:05?

<!-- AWP_In_Variable Name='"webdata".Takt' -->

<div class="takt">
    <p>TAKT</p>
    <div class="Takt" id="takt">:="webdata".Takt:</div>
</div>

This <!-- AWP_In_Variable Name='"webdata".Takt' --> is how I get the information from the PLC web server.

Riza Khan
  • 2,712
  • 4
  • 18
  • 42
  • 1
    Can you provide more information about what template language you are using? It would help in providing you with a solution. – Chris Jul 15 '20 at 22:36
  • I'm using JS and Jquery to take and update the information in HTML – Felipe Deolindo Jul 15 '20 at 22:48
  • Does this answer your question? [How can get the text of a div tag using only javascript (no jQuery)](https://stackoverflow.com/questions/10370204/how-can-get-the-text-of-a-div-tag-using-only-javascript-no-jquery) –  Jul 17 '20 at 09:18

2 Answers2

0

Assuming the time returned from the server is in the #id 'takt':

const targetNode = document.getElementById('takt');
const time = targetNode.innerText;
targetNode.innerText = time.replace('#T', '').replace('_', ':');
uke5tar
  • 399
  • 3
  • 8
0

If all you want to do is change the div contents you could place a script at the bottom of your html page, right before the closing body tag.

<body>

<!-- AWP_In_Variable Name='"webdata".Takt' -->

<div class="takt">
    <p>TAKT</p>
    <div class="Takt" id="takt">:="webdata".Takt:</div>
</div>

<script>
    var webData = document.getElementById('takt');
    var content = webData.innerText;

    webData.innerText = content.replace('#T', '').replace('_', ':');
</script>
</body>

Going this route would expect that the information coming from your PLC is always formatted as #T{hour}_{minute}. If your format may be different then a different approach would need to be taken. This specific code would transform #T15_05 to be 15:05

Chris
  • 1,484
  • 1
  • 12
  • 19