Reputation: 533
I am trying to append()
a button with an onclick
attribute which calls a javascript function:
$('#button').append('<button onclick=setUrlLink(\''+pageN+'\')>Next</button>);
When checking the source code, quotations are missing around pageN
, how can I do that?
Upvotes: 0
Views: 88
Reputation: 55740
Why not use Double Quotes
$('#button').append('<button onclick=setUrlLink("'+pageN+'")>Next</button>');
----^ ^---
Upvotes: 4
Reputation: 191749
Why not just use jQuery to do that?
$("#button").append($("<button>").on('click', function () { setUrlLink('pageN'); })
.text('Next'));
Upvotes: 3
Reputation: 8050
Just use double quotes to start the string instead of single quotes.
$("#button").append("<button onclick=setUrlLink('" +pageN+ "')>Next</button>");
Upvotes: 0