tags:

views:

123

answers:

3
"<div id="diva">this is div a</div>"
"<div id="divb"> this is div b</div>"

now how can I change the text of div dynamically by button click. here also mention that all text come from a database. when I click the button then it detects the div id and replace the text with desire text.

All code will be in PHP.

+3  A: 

PHP cannot modify the content of the page after it has been served to the browser. However this would be trivial with a JavaScript Library such as jQuery.

beggs
+2  A: 

Using javascript you can change the text after rendering the page in the client browser. ex:

document.getElementById('diva').innerHTML="New text goes here";

You can find more about javascript dom here.

The data to be displayed can be fetched from the server at runtime using a AJAX request

Arun P Johny
+3  A: 

This will work once the page is being loaded:

document.getElementById('diva').innerHTML = 
  <?php echo functionThatReturnsSomeValue(); ?>;

Dynamically, you would need to do an AJAX call on the PHP file which outputs a value. You'd be better off if you used a JS framework such as jQuery, rather than implementing the AJAX call yourself.

Wesho