CCates
CCates

Reputation: 1255

Javascript not working with PHP echo statements

So, I'm using jQuery with PHP, and, I am echoing out a button:

echo '<input type="button" id="button" value="Info" style="float: right;"/>';

Pretty simple, I tried using "\" for the quotations, but, that didn't make any difference (for those who will point it out.

Anyway, the jQuery portion is pretty simple:

        $("#button").click(function() {
        alert("Clicked");
    });

Within the $(document).ready(function(){});

The echo is passed through an ajax call. If that makes any difference, and.

I do not get the alert. So if anyone can pinpoint the solution that would be great.

Upvotes: 0

Views: 770

Answers (2)

Daniel
Daniel

Reputation: 458

Try using " instead of ' for the quotes on the outside as PHP does not evaluate things inside single quotes.

Upvotes: 0

Ken Wheeler
Ken Wheeler

Reputation: 1958

echo '<input type="button" id="button" value="Info" style="float: right;"/>';

$("input#button").live('click',function() {
        alert("Clicked");
});

Upvotes: 3

Related Questions