Replace text (with paragraphs) with a button


#1

I’m trying to do something like this, except when I press the button I want that every paragraph have a different text. For example, in “This is a paragraph” display “Hello world” and in “This is another paragraph” display “Bye world”. Is that possible? I want to do this so bad :confused: Thank you for the help!

< script src=“https://ajax.googleapis.com/ajax/libs/jquery/1.12.2/jquery.min.js”>< /script> < script> $(document).ready(function(){ $(“button”).click(function(){ $(“p”).text(“Hello world!”); }); }); < /script> < /head> < body>

< button>Set text content for all p elements< /button>

< p>This is a paragraph.< /p> < p>This is another paragraph.< /p>


#2

You may try something like below,

<script>
    function changePara () {
     var getDiv = document.getElementById('paraGraph');
     getDiv.innerHTML = 'Bye World';
    }
    </script>

<input type='button' onclick='changePara ()' value='Change!'/>
<div id='paraGraph'>
 Hello World
</div>

Try above code here http://editor.mybloggertricks.com/