0

function check() {
  var para = document.getElementsByTagName("p");
  para[0].style.fontSize = 20;
}
<p>This a paragraph</p>
<p>This a paragraph</p>
<p>This a paragraph</p>
<p>This a paragraph</p>
<button onClick="check()">Check</button>

please check the script section I am not able to find any error please help me this

1
  • what is it supposed to do? Commented Mar 16, 2020 at 8:20

3 Answers 3

5

Specify font size in pixels inside string instead of using number 20. Also move the script tag to bottom of body tag.

Please find the working snippit below:

    function check()
    {
        var para=document.getElementsByTagName("p");
        para[0].style.fontSize= '20px' ;
    }
    <p>This a paragraph</p>
    <p>This a paragraph</p>
    <p>This a paragraph</p>
    <p>This a paragraph</p>
    <button onclick="check()">Check</button>

Sign up to request clarification or add additional context in comments.

Comments

0

For each Tag P must use like this...

js

function check() {
  var s=document.getElementsByTagName('p');
  for(i=0;i<s.length;i++)
  {
    s[i].setAttribute("style","font-size:20px");
  }
}

View

<p>This a paragraph</p>
<p>This a paragraph</p>
<p>This a paragraph</p>
<p>This a paragraph</p>
<button onClick="check()">Check</button>

Comments

0

you have to define the size in string with px,em,% behind and wrap it with quote

para[0].style.fontSize = 20;

to

para[0].style.fontSize = "20px";

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.