0

I am trying to replace the content of a DIV once the button inside that DIV is clicked, (basically replacing the button, which retreives a PHP variable:

<div id="buttonholder">
<a href="#" onClick="return false" onmousedown="javascript:publish('<?php echo $id;?>');">Publish</a>
</div>

I am trying to replace it with an unpublish button after a post is published (when the button above is clicked):

function publish(status){
document.getElementById("buttonholder").innerHTML = '<a href="#" onClick="return false" onmousedown="javascript:publish('<?php echo $id;?>');">Unpublish</a>';
}

It does not work however ... What am I doing wrong ?

1
  • It does not work however That tells us nothing. What is the error message in the browser's console? Commented Jul 25, 2014 at 13:17

2 Answers 2

2

Your code syntax is wrong. Use like below.

function publish(status){
document.getElementById("buttonholder").innerHTML = '<a href="#" onClick="return false" onmousedown="javascript:publish(\'<?php echo $id;?>\');">Unpublish</a>';
}
Sign up to request clarification or add additional context in comments.

1 Comment

Thank you RajivRisi ! Worked perfectly ! Yes I had trouble with the ' apostrophes
0

Add a button id and then do:

$(function() {
    $("#buttonId").click(function() {
        $("#buttonHolder").html(" html to replace with ");
    });
});

Also you can use the $("#buttonHolder").html(" html to replace with "); instruction in your onClick function as well.

3 Comments

There's no jQuery in his question title or original code so you shouldn't recommend a solution that relies on it.
It's an exercise of imagination
Thanks, Andrew, but it does not work ... I think it is the mess of all those apostrophes " and ' and that PHP block, it breaks everything ...

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.