<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[The best way to change styles for inner HTML]]></title><description><![CDATA[<p>From backend I receive payload that contains rich text fields. The problem is that I need to update properties for links included in these texts.<br />
I was thinking to use <code>DOMParser</code> like so:</p>
<pre><code>  const parsed = new DOMParser().parseFromString(this.innerHtml, &quot;text/html&quot;);

  const links = parsed.getElementsByTagName(&quot;a&quot;);

  Array.from(links).forEach((link) =&gt; {
    link.setAttribute(&quot;href&quot;, &quot;#&quot;);
    link.style.textDecoration = &quot;none&quot;;
    link.style.color = &quot;inherit&quot;;
    link.style.cursor = &quot;text&quot;;
    link.onclick = (event) =&gt; event.preventDefault();
  });
</code></pre>
<p>However, when I try to run such code, I receive error message that <code>DOMParser</code> is not defined .</p>
<p>Then, I tried to use <code>jsdom</code>, but statement</p>
<pre><code>const { JSDOM } = require('jsdom');
</code></pre>
<p>produces error &quot;Unable to require module jsdom. resolveModulePath is not a function&quot;. I have <code>24.0.0</code> version of <code>jsdom</code> and <code>21.6.2</code> version of <code>Node</code> installed.</p>
<p>If you know, could you, please, help me to find solution for this problem. I understand that using regex is always an option, but usually pretty unreliable one when it comes to parsing HTML. So, I'd prefer to avoid it if there are better alternatives</p>
]]></description><link>https://forum.jsreport.net/topic/3150/the-best-way-to-change-styles-for-inner-html</link><generator>RSS for Node</generator><lastBuildDate>Tue, 11 Aug 2026 11:12:40 GMT</lastBuildDate><atom:link href="https://forum.jsreport.net/topic/3150.rss" rel="self" type="application/rss+xml"/><pubDate>Tue, 16 Apr 2024 12:30:43 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to The best way to change styles for inner HTML on Invalid Date]]></title><description><![CDATA[<p>From backend I receive payload that contains rich text fields. The problem is that I need to update properties for links included in these texts.<br />
I was thinking to use <code>DOMParser</code> like so:</p>
<pre><code>  const parsed = new DOMParser().parseFromString(this.innerHtml, &quot;text/html&quot;);

  const links = parsed.getElementsByTagName(&quot;a&quot;);

  Array.from(links).forEach((link) =&gt; {
    link.setAttribute(&quot;href&quot;, &quot;#&quot;);
    link.style.textDecoration = &quot;none&quot;;
    link.style.color = &quot;inherit&quot;;
    link.style.cursor = &quot;text&quot;;
    link.onclick = (event) =&gt; event.preventDefault();
  });
</code></pre>
<p>However, when I try to run such code, I receive error message that <code>DOMParser</code> is not defined .</p>
<p>Then, I tried to use <code>jsdom</code>, but statement</p>
<pre><code>const { JSDOM } = require('jsdom');
</code></pre>
<p>produces error &quot;Unable to require module jsdom. resolveModulePath is not a function&quot;. I have <code>24.0.0</code> version of <code>jsdom</code> and <code>21.6.2</code> version of <code>Node</code> installed.</p>
<p>If you know, could you, please, help me to find solution for this problem. I understand that using regex is always an option, but usually pretty unreliable one when it comes to parsing HTML. So, I'd prefer to avoid it if there are better alternatives</p>
]]></description><link>https://forum.jsreport.net/post/13496</link><guid isPermaLink="true">https://forum.jsreport.net/post/13496</guid><dc:creator><![CDATA[alexey-boiko]]></dc:creator><pubDate>Invalid Date</pubDate></item><item><title><![CDATA[Reply to The best way to change styles for inner HTML on Invalid Date]]></title><description><![CDATA[<p>In case you use <code>chrome-pdf</code> recipe... Can't you do this with inline javascript instead of modifying the html? <code>&lt;script&gt;...&lt;/script&gt;</code>. It would be performing better since you have the dom already loaded in chrome.</p>
<p>There is some error in the require of jsdom, we will look at it <a href="https://github.com/jsreport/jsreport/issues/1128" rel="nofollow">here</a>.<br />
Please use another lib like cheerio till then<br />
<a href="https://playground.jsreport.net/w/anon/NE34uLwD" rel="nofollow">https://playground.jsreport.net/w/anon/NE34uLwD</a></p>
]]></description><link>https://forum.jsreport.net/post/13500</link><guid isPermaLink="true">https://forum.jsreport.net/post/13500</guid><dc:creator><![CDATA[admin]]></dc:creator><pubDate>Invalid Date</pubDate></item><item><title><![CDATA[Reply to The best way to change styles for inner HTML on Invalid Date]]></title><description><![CDATA[<p>Yeah, inline script worked out. Thanks</p>
]]></description><link>https://forum.jsreport.net/post/13514</link><guid isPermaLink="true">https://forum.jsreport.net/post/13514</guid><dc:creator><![CDATA[alexey-boiko]]></dc:creator><pubDate>Invalid Date</pubDate></item></channel></rss>