<?xml version="1.0" encoding="UTF-8"?>
<feed xmlns="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <title>Liferay Page Fragments - How to use JavaScript correctly</title>
  <link rel="self" href="https://liferay.dev/c/message_boards/find_thread?p_l_id=119785294&amp;threadId=120544668" />
  <subtitle>Liferay Page Fragments - How to use JavaScript correctly</subtitle>
  <id>https://liferay.dev/c/message_boards/find_thread?p_l_id=119785294&amp;threadId=120544668</id>
  <updated>2026-07-12T18:13:51Z</updated>
  <dc:date>2026-07-12T18:13:51Z</dc:date>
  <entry>
    <title>Liferay Page Fragments - How to use JavaScript correctly</title>
    <link rel="alternate" href="https://liferay.dev/c/message_boards/find_message?p_l_id=119785294&amp;messageId=120544667" />
    <author>
      <name>Daniel Betz</name>
    </author>
    <id>https://liferay.dev/c/message_boards/find_message?p_l_id=119785294&amp;messageId=120544667</id>
    <updated>2021-01-11T15:10:04Z</updated>
    <published>2021-01-11T13:37:25Z</published>
    <summary type="html">&lt;p&gt;The question might sound a little irretating and I don't want advice
  with JS syntax, I need to know how I USE JS in a page fragment. No
  matter what I tried, JS won't work. I tried the bottom left JavaScript
  part, but calling functions inside it doesn't work. Then I decided to
  use the &amp;lt;script&amp;gt;&amp;lt;/script&amp;gt; Tag in the HTML part, still
  doesn't do anything. I develop on a local isntance on a linux machine,
  but a colleague of mine has the same problem after  I sent him the code.&lt;/p&gt;
&lt;p&gt; &lt;/p&gt;
&lt;p&gt;Here is the code:&lt;/p&gt;
&lt;pre&gt;&lt;code class="language-html"&gt;&amp;lt;div class=&amp;quot;hvrbox&amp;quot;&amp;gt;
		&amp;lt;lfr-editable id=&amp;quot;image-square&amp;quot; type=&amp;quot;image&amp;quot;&amp;gt;
		&amp;lt;img alt=&amp;quot;Responsive Image&amp;quot; class=&amp;quot;${configuration.imageSize} hvrbox-layer_bottom&amp;quot; src=&amp;quot;data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAJCAYAAAA7KqwyAAAACXBIWXMAAAsTAAALEwEAmpwYAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAAkSURBVHgB7cxBEQAACAIwtH8Pzw52kxD8OBZgNXsPQUOUwCIgAz0DHTyygaAAAAAASUVORK5CYII=&amp;quot; /&amp;gt;
	&amp;lt;/lfr-editable&amp;gt;
	&amp;lt;div class=&amp;quot;hvrbox-layer_top&amp;quot;&amp;gt;
		&amp;lt;div class=&amp;quot;hvrbox-text&amp;quot;&amp;gt;
		  &amp;lt;button type=&amp;quot;button&amp;quot; onclick=&amp;quot;change()&amp;quot;&amp;gt;Click Me!&amp;lt;/button&amp;gt;
		  &amp;lt;lfr-editable id=&amp;quot;element-text&amp;quot; type=&amp;quot;rich-text&amp;quot;&amp;gt;
		   Hier könnte Ihre Werbung stehen
	    &amp;lt;/lfr-editable&amp;gt;
		&amp;lt;/div&amp;gt;
	&amp;lt;/div&amp;gt;
&amp;lt;/div&amp;gt;

&lt;/code&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;code class="language-javascript"&gt;function change() {
    document.getElementById(&amp;quot;element-text&amp;quot;).innerHTML = &amp;quot;Hello Javascript&amp;quot;
}&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt; &lt;/p&gt;
&lt;p&gt;Unless I'm doing somthing terribly wrong, I don't see why this isn't
  working. Is there a special way to use the &amp;quot;JavaScript&amp;quot;
  section? After all, it says: &amp;quot;&lt;code
    class="source-editor__fixed-text__content"&gt;function(fragmentElement,
    configuration) {&amp;quot; in the frame of it&lt;/code&gt;&lt;/p&gt;</summary>
    <dc:creator>Daniel Betz</dc:creator>
    <dc:date>2021-01-11T13:37:25Z</dc:date>
  </entry>
</feed>
