Search code examples
javascripthtmlalertgetelementbyid

Alert not getting inner HTML?


I am trying to get my java script file to capture the inner Html of an id in my HTML file and alert it.

here is my html code

<head>
 <script type="text/javascript" src="indexjs.js"></script>
</head>
<body>
  <div class="topbar">
 <ul>
  <li id="barmuhia">Job Muhia</li>
</ul>
 </div>
</body>

the js code is

alert(GetElementById("barmuhia").innerHTML)

Solution

  • Hi You are missing document and using GetElementById instead of getElementById here, use below

    alert(document.getElementById("barmuhia").innerHTML);
    

    you can also use below jquery method

    $("#barmuhia").html()