hinata hinata - 9 months ago 46
Javascript Question

Changing button text by Click in JavaScript

I'm using following codes in a JSP page.This is my function to change button text by a button click in JavaScript.

function click(){
var el=document.getElementById(btnaccept);

This is my button;

<button type="button" class="btn btn-default btn-sm" id="btnaccept" onclick="click()">
<span class="glyphicon glyphicon-ok" aria-hidden="true" name="accept"></span> Accept

This code is not functioning when I click the "Accept" button. What error I have done here?


Try this code

      function click1() {
        var el = document.getElementById('btnaccept');
        if (el.textContent == "Accept") {
          el.textContent = "Accepted";
        } else {
          el.textContent = "Accept";

change onclick event to click1()