Note that there are some explanatory texts on larger screens.

plurals
  1. POUsing prototype javascript to set heading styles
    primarykey
    data
    text
    <p>I'm trying to create H2 headings using prototype so they can be set individually as required. </p> <p>I'm using <code>this.appendChild(document.createTextNode(''));</code> to add text to the <code>H2</code>. I need to use the parent node before <code>appendChild</code> which I believe in this case is the <code>this</code> keyword but I'm not sure it's being recognised as the parent or if it actually is the parent ? I'm also uncertain as of how to add the text through a parameter of the constructor itself . I've used a variable 'font' but not sure how to make it work as its not adding a css style ?</p> <p>I'm learning how to use prototype so if there's any other obvious errors I've missed please let me know.</p> <pre><code>&lt;div id='body'&gt; &lt;div id='inner'&gt;div here&lt;/div&gt; &lt;/div&gt; &lt;script&gt; Heading.prototype.font; Heading.prototype.color; Heading.prototype.fontSize; Heading.prototype.headingTxt; Heading.prototype.setHeading = function() { var inner = document.getElementById('inner'); this.headingTxt = document.createElement('h2'); this.headingTxt.font = this.appendChild(document.createTextNode('')); this.headingTxt.style.color = this.color; this.headingTxt.style.fontSize = this.fontSize; inner.appendChild(headingTxt); } function Heading(font, color, fontSize) { this.font = font; this.color = color; this.fontSize = fontSize; } var title = new Heading('heading here', 'red', 20); title.setHeading(); &lt;/script&gt; </code></pre> <p>Can anyone help me how can resolve this issue ?</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload