I am looking to extract and log a JavaScript-calculated result from an anonymous survey created using a WordPress plugin.
The generated HTML code is:
<div ref="fieldname57_1" class="cff-summary-item">
<span class="summary-field-title cff-summary-title">Yearly costs</span>
<span class="summary-field-value cff-summary-value">£120</span></div>
(...)
When rendered, it looks like this:
Yearly costs: £120
Monthly costs: 10
This formatting is achieved through the use of CSS, for instance:
fbuilder .cff-summary-title:after {
content: ': ';
}
To capture and post the text for logging using a basic jQuery post handler, I can do something like this:
var stuff = jQuery('#fieldname66_1').text();
jQuery.post( "/formpost.txt", { name: "result", value: stuff } );
However, the output ends up being
Yearly costs£120Monthly costs£10
.
If I retrieve jQuery('#fieldname66_1').html()
, then I have to deal with the HTML structure.
One option could be to explore backend processing utilizing Node.js and relevant npm packages.
While I am familiar with jQuery's array functions, they still return HTML data. I could potentially utilize the .next() method to iterate through the spans and store the results in an array.
But... am I overlooking a more efficient solution?
When I mention "logging," it doesn't necessarily need to follow a specific line-by-line format.
I aim to log the entire div "as is." Unfortunately, modifying the plugin code is not an option.
The entire page content is dynamically rendered via JavaScript in the browser.
Appreciate your help!