IntricatePixels
IntricatePixels

Reputation: 1229

jquery pass text and variable inside .html()

this is probably very easy but I can't figure it out :)

 $('#myDiv').html('<a onclick="remove_item(variantId);">Remove</a>');

variantId is a JS variable so I need to pass it's value in the code above.

Upvotes: 3

Views: 7623

Answers (3)

JBLew
JBLew

Reputation: 33

$('#myDiv').html('<a onclick="remove_item('+variantId+');">Remove</a>');

Upvotes: 0

Alpesh
Alpesh

Reputation: 5405

use it this way -

 $('#myDiv').html('<a onclick="remove_item('+variantId+');">Remove</a>');

Upvotes: 0

Sjoerd
Sjoerd

Reputation: 75588

 $('#myDiv').html('<a onclick="remove_item(' + variantId + ');">Remove</a>');

Upvotes: 4

Related Questions