Klaus Turbo
Klaus Turbo

Reputation: 2960

How can I use image_tag in a javascript response?

I'm trying to realize following:

$(".share-icon").html("<%= image_tag(@card.photo.url(:small)) %>");

This is obviously not working but how can I use image_tagin a JS response?

Thanks

Upvotes: 0

Views: 641

Answers (1)

jvnill
jvnill

Reputation: 29599

try escaping the html generated by image_tag using escape_javascript

$(".share-icon").html("<%= escape_javascript image_tag(@card.photo.url(:small)) %>");

Upvotes: 2

Related Questions