javascript - Setting button title in HTML to a non-formatted text -
i have simple html page
<body> <button type="button" id="button1" onclick="foo()">result!</button> <script type="text/javascript"> function foo() { var button = document.getelementbyid("button1"); } </script> </body>
i want change button title on click.
title might include html tags , want presented (without formatting).
i've tried way suggested in this post , works great regular text. unfortunately formats html tags , doesn't present non-formatted text:
<body> <button type="button" id="button1" onclick="foo()">result!</button> <script type="text/javascript"> function foo() { var button = document.getelementbyid("button1"); button.innerhtml = "<strong>my text</strong>" } </script> </body>
to clear, want title <strong>my text</strong>
, not my text.
so right way present non-formatted text inside button?
the innertext attribute work:
<body> <button type="button" id="button1" onclick="foo()">result!</button> <script type="text/javascript"> function foo() { var button = document.getelementbyid("button1"); button.innertext = "<strong>my text</strong>" } </script> </body>
note: firefox doesn't support innertext, has own property called textcontent, can used instead.
Comments
Post a Comment