Dev123
Dev123

Reputation: 56

how to dataurl with knockout data-bind

How to display an image in knockout using dataurl?

I have an observable in knockout with value set as dataurl for an image. I want to bind this image to html-5 data-bind attribute of span element.

Currently, the image is not getting displayed. Can anyone help me with the syntax?

Sample code:

'<'span style="display:block; width:96px; height:95px;" data-bind="style:{backgroundImage: 'url(data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAA'}"></span>

Upvotes: 0

Views: 1141

Answers (1)

haim770
haim770

Reputation: 49095

You're simply missing the closing ) of the url. Try this:

<span style="display:block; width:96px; height:95px;"
      data-bind="style: { backgroundImage: 'url(data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAA)' }"></span>

See Fiddle: http://jsfiddle.net/J8VNY/3/

Upvotes: 1

Related Questions