Javascript Change text when button is clicked -
hi want change text inside div when button click.
<div> <p id="part1">hello</p> <button type="button" onclick="myfunction()">next</button> </div> <script> function myfunction() { document.getelementbyid("part1").innerhtml="world"; } </script>
this works perfectly. have div has text , button inside, in case has word "hello". code have when click button word "hello" change word "world". want make sequence change word "hello" "world", "world" "welcome" , "welcome" "my program" (example). , clicking button multiple times.
if looking text change cycle
happen try this:-
var textarray=['world', 'my', 'welcome', 'something','hello'] function myfunction() { var value = textarray.shift(); //get first item array textarray.push(value); //push cycle repeat. document.getelementbyid("part1").innerhtml=value; }
Comments
Post a Comment