Art Planteur
Art Planteur

Reputation: 533

Append quotation

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

Answers (3)

Sushanth --
Sushanth --

Reputation: 55740

Why not use Double Quotes

$('#button').append('<button onclick=setUrlLink("'+pageN+'")>Next</button>');
                                            ----^         ^---

Upvotes: 4

Explosion Pills
Explosion Pills

Reputation: 191749

Why not just use jQuery to do that?

$("#button").append($("<button>").on('click', function () { setUrlLink('pageN'); })
   .text('Next'));

Upvotes: 3

Jason Towne
Jason Towne

Reputation: 8050

Just use double quotes to start the string instead of single quotes.

$("#button").append("<button onclick=setUrlLink('" +pageN+ "')>Next</button>");

Upvotes: 0

Related Questions