# Could somebody help,JavaScript code is not executing ?

**URL:** <https://forum.kirupa.com/t/could-somebody-help-javascript-code-is-not-executing/634676>\
**Category:** web dev\
**Created:** [May 25, 2016, 5:51am UTC](https://forum.kirupa.com/t/could-somebody-help-javascript-code-is-not-executing/634676 "2016-05-25T05:51:40Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Swati1](https://avatars.discourse-cdn.com/v4/letter/s/cab0a1/32.png) [@Swati1](https://forum.kirupa.com/u/Swati1)\
**Post date:** [May 25, 2016, 5:51am UTC](https://forum.kirupa.com/t/could-somebody-help-javascript-code-is-not-executing/634676/1 "2016-05-25T05:51:40Z")

</div>

This is an HTML 5 code,and I am using visual studio code . Though ,HTML part is giving output but there is no change in header after applying JavaScript code to it. I don’t seem to understand the problem. Pls help.

```auto
<!DOCTYPE html>
<html lang="en-US">
<head>
<title>HTML Page</title>
</head>
<body>
<header id="headerItem"> Old Header </header>

<section> 
<button>Click Here</button> 
</section>

<script type="text/javascript">

function startLogic() {

var newHtml =
'<em>New Header</em>';

document.getElementById

('headerItem').innerHTML =

newHtml; }

startLogic();

</script>

</body>
</html>

```

---

<div class="post-metadata">

**Author:** ![senocular](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/senocular/32/7217_2.png) [@senocular](https://forum.kirupa.com/u/senocular)\
**Post date:** [May 25, 2016, 3:37pm UTC](https://forum.kirupa.com/t/could-somebody-help-javascript-code-is-not-executing/634676/2 "2016-05-25T15:37:38Z")

</div>

I put it in a fiddle and it works fine: [https://jsfiddle.net/bvz8p4md/](https://jsfiddle.net/bvz8p4md/)

P.S. When pasting code into a post, be sure to format it correctly so that it comes through using either the formatting toolbar (\</\>), indenting with 4 spaces, or surrounding it with 3 backticks (`).

---

<div class="post-metadata">

**Author:** ![Swati1](https://avatars.discourse-cdn.com/v4/letter/s/cab0a1/32.png) [@Swati1](https://forum.kirupa.com/u/Swati1)\
**Post date:** [May 25, 2016, 4:15pm UTC](https://forum.kirupa.com/t/could-somebody-help-javascript-code-is-not-executing/634676/3 "2016-05-25T16:15:22Z")

</div>

Thanks senocular .  
I realised later today that, though the code I posted in my question was correct but while writing the code in the file, I wrote ‘header’ instead of ‘headerItem’ and hence ,the reason of non execution of program.

---

<div class="post-metadata">

**Author:** ![senocular](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/senocular/32/7217_2.png) [@senocular](https://forum.kirupa.com/u/senocular)\
**Post date:** [May 25, 2016, 4:25pm UTC](https://forum.kirupa.com/t/could-somebody-help-javascript-code-is-not-executing/634676/4 "2016-05-25T16:25:41Z")

</div>

That happens to the best of us 😉

---

<div class="post-metadata">

**Author:** ![TheCanadian](https://avatars.discourse-cdn.com/v4/letter/t/67e7ee/32.png) [@TheCanadian](https://forum.kirupa.com/u/TheCanadian)\
**Post date:** [May 26, 2016, 4:30am UTC](https://forum.kirupa.com/t/could-somebody-help-javascript-code-is-not-executing/634676/5 "2016-05-26T04:30:02Z")

</div>

It also happens to the worst of us :run\_in\_fear:
